Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 seperate 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 know 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 &
share|improve this question
this should work the way it is written in the question (after the first edit made it a bit nonsensical) – hop Oct 1 '10 at 12:37
@hop I really don't know what you're talking about, the first edit added a newline and formatted the shell parts as code so they would display properly. I changed virtually nothing, the original revision is here – Michael Mrozek Oct 1 '10 at 14:22
@Michael: you are right and i'm sorry. i misinterpreted the diff and thought, you had added the backticks. makes the question even more nonsensical: the example as given should work. – hop Oct 1 '10 at 14:32
@hop The perl one? I assumed it didn't work without trying as I don't know perl, but I guess he said "I don't know if the following will work", so maybe it is fine; you should probably just answer that the given example works – Michael Mrozek Oct 1 '10 at 14:46

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

share|improve this answer
+1: I haven't seen yes used in eons – msw Oct 1 '10 at 4:23
Michael, thank you for your prompt reply. However, I think I've tried your suggestion whereby I echo Y into the process. When I've done this, the output always spills onto my terminal despite the fact that I've ensured an & is in my – Sandeep Oct 1 '10 at 8:17
The & doesn't prevent the process output to be written to console. It just starts it in the background. – fschmitt Oct 1 '10 at 9:20
how has this answer anything to do with the question? – hop Oct 1 '10 at 12:15
@Riccardo I experimented a little, and I think you're right. Fixed, thanks – Michael Mrozek Oct 1 '10 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.