in reply to automatically giving user input to a command line

What you have tried cannot work.

When you use backticks you get control back only AFTER the command has finished, which of course is too late for your purpose.

Expect should be what you need, something like:

use strict; use Expect; my $ex = Expect->spawn(undef, "Command foo") or die $! $ex->expect(undef, "-re", "Do you want to read the file"); $ex->send("1\n");
This spawns your command in parallel to your script and waits for your prompt to appear. It then sends a "1" back to the command, simulating a user input (depending on how your command reads it's input you may or may not have to send the newline - you have to experiment there).

If you want you can add a timeout as the first parameter to the expect-call (undef means wait forever for the pattern to appear which may or may not be what you want).

Replies are listed 'Best First'.
Re^2: automatically giving user input to a command line
by tfredett (Sexton) on Jun 14, 2012 at 14:47 UTC
    I am currently in the process of obtaining Expect, however I ran into some errors installing it properly, and from what I have researched, I can not do it properly without cygwin. So I am in the process of installing it on my work system (Why I didn't have it before I don't know. I normally do) and as soon as I get it, I should be able to install it and start testing with it.