Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm wondering if this is at all possible (even with perl) I am calling a program via the "sytem" command and every so often the user is prompted with a Yes/No question. I wonder if its possible to automatically use <STDIN> to answer? I know "system" doesn't return control until its done executing its specified command.
Folder C:\AB\Bin not found, create?(Y/N)

Replies are listed 'Best First'.
Re: Posing Question
by atcroft (Abbot) on Jun 04, 2002 at 17:11 UTC

    While I have not looked at it in some time, especially for what you seem to be asking, you may wish to take a look at the Expect module, which (in my limited understanding) I believe was written for just the situations you are inquiring about.

    Update: I thought that last line was a signature, but if that is a line you're seeing as a result of your system call, why not use the mkdir command? Just a thought....

Re: Posing Question
by Aristotle (Chancellor) on Jun 05, 2002 at 07:08 UTC
    Since you're on a DOSish system where pipes are only halfheartedly implemented, you'll have trouble any way you try to solve this. I'm not sure Expect will do anything for you. If I'm guessing correctly here, however, you're using this to control an archiver (ARJ by any chance? or am I off by a long shot?), most of which have a commandline switch to automatically confirm any prompts. You might want to look into that.

    Makeshifts last the longest.

Re: Posing Question
by {NULE} (Hermit) on Jun 05, 2002 at 02:20 UTC
    Hi Anonymous Monk,

    I haven't played with the Expect module as Atcroft suggests so it may be a better solution than what I pose here. But you can probably do this using open2 or open3 on a *nix system. That will return a filehandle for the other processes STDIN and STDOUT (and STDERR with open3). These you could use select on (IO::Select for your own sanity) and then when it is ready for writing, send it your expected response. This is untested, but a filehandle is a filehandle, right? So it should work.

    But if you are really doing this to make directories, do a mkdir like Atcroft suggests, please. :)

    Good luck,
    {NULE}
    --
    http://www.nule.org