Execute Nohup command with input

nohupperlprocess

In UNIX, I have a process that I want to run using nohup. However, this process will at some point wait at a prompt where I have to enter yes or no for it to continue. So far, in UNIX I have been doing the following:

nohup myprocess <<EOF
y
EOF

So I start the process 'myprocess' using nohup and pipe in a file with 'y' then close the file. The lines above are effectively three separate commands – i.e. I hit enter on the first line in UNIX, then I get a prompt where I enter 'y' and then press enter to then finally type 'EOF' and hit return again. So this works perfectly, but my problem is below.

I want to now execute this in Perl, but I am not sure how I can execute this command, as it is over three lines. I don't know if the following will work:

my $startprocess = `nohup myprocess <<EOF &
y
EOF
`

Best Answer

If you just want to write a single y to the stdin of the process, you can do this:

(echo y | nohup myprocess) &

If you want to keep writing y for every prompt that comes up, the coreutil yes exists for exactly this purpose -- it will keep writing whatever you tell it to to stdout. Its default is to output "y", so you can just:

(yes | nohup myprocess) &

but if you need something else you can pass it as an argument

Related Question