Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

STDIN

by Anonymous Monk
on Nov 18, 2002 at 23:47 UTC ( [id://213991]=perlquestion: print w/replies, xml ) Need Help??

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

I have a program that is being run via a system call in my perl script, and its prompting me for a yes or no answer.

Is it possible to force input for STDIN?

while (<STDIN>) { print "y"; }
Pls help

Replies are listed 'Best First'.
Re: STDIN
by Ovid (Cardinal) on Nov 19, 2002 at 00:05 UTC
Re: STDIN
by Zaxo (Archbishop) on Nov 19, 2002 at 00:33 UTC

    More sick and evil stuff!

    { open local(*STDIN), '<', \"yes\n" or die $!; system @the_args; }

    Again, this is a perl 5.8 PerlIO trick, a little more apt this time.

    After Compline,
    Zaxo

Re: STDIN
by submersible_toaster (Chaplain) on Nov 19, 2002 at 00:05 UTC

    Yeaas, and as usual there are a million permutations. Some simple ones leap to mind.

    system ( "echo yes | /usr/bin/querrelous" );

    which obviously will only work for the one 'yes'or'no'

    open ( SYS "|/usr/bin/querrelous" ); print SYS 'yes' , $/;
    For anything more complicated maybe you should think about IPC::Open2 for talking and listening to your process.
    submersible_toaster bashing buttons
Re: STDIN
by rob_au (Abbot) on Nov 19, 2002 at 00:06 UTC
    You will want to have a look at the Expect module which will handle interactive tasks without operator assistance. The documentation for this module includes an extensive list of frequently asked questions about how to make things work.

     

    perl -e 'print+unpack("N",pack("B32","00000000000000000000000111100110")),"\n"'

Re: STDIN
by bluto (Curate) on Nov 19, 2002 at 00:08 UTC
    The unix 'yes' command prints 'y' or 'yes', depending on your system type, or whatever string you put on the command line to STDOUT. So you should be able to do this...
    system("yes y | command");

    bluto

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://213991]
Approved by Ovid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found