Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

User input while process is running.

by siva.snimmaka (Initiate)
on Aug 05, 2013 at 13:13 UTC ( [id://1047909]=perlquestion: print w/replies, xml ) Need Help??

siva.snimmaka has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am invoking a unix process from a perl script. Would like give user input to the process, while it is running. Any suggestions on how to do this??? Thanks, SIN

Replies are listed 'Best First'.
Re: User input while process is running.
by rjt (Curate) on Aug 05, 2013 at 13:31 UTC

    Have a look at IPC::Run for a robust implementation of this, or for simple uses that don't require pty emulation and you don't need to capture the output, open will do what you want. Here's a barebones look at both:

    use 5.010; use autodie; # With basic open() open my $sort, '|-', 'sort -n'; printf $sort "%d\n", rand 100 for 1..10; close $sort; # With IPC::Run use IPC::Run qw/start finish pump/; print "IPC::Run output:\n"; my $r = start [ 'perl' ], \my $in, \my $out, \my $err or die "Can't start: $!"; $in .= 'print "Hello, world!\n";'; finish $r; say $out; die 'ERROR: $err' if length $err;

    Output:

    13 14 34 37 44 63 83 86 90 95 IPC::Run output: Hello, world!
    use strict; use warnings; omitted for brevity.
Re: User input while process is running.
by glasswalk3r (Friar) on Aug 05, 2013 at 15:04 UTC

    See perlipc for general information: there are several ways to do that.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re: User input while process is running.
by Anonymous Monk on Aug 05, 2013 at 15:37 UTC
    HI, While using expect i am getting some error.. <<<<SNIPPET>>> Can't locate Expect.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at upgrade.pl line 5. BEGIN failed--compilation aborted at upgrade.pl line 5. To know the issue better, i am pasting here the output i need to handle: While invoking the upgrade.sh script via a perl script, it will have the output.... =========================================================== root@TB3# ./UPGRADE.sh Upgrade takes time to complete. Do not press CTRL-C hereafter. Stopping the service... ./catalina.sh: line 330: /usr/java/jdk1.6.0_31/bin/java: No such file or directory Verifying the CAM db schema... CAM db schema is valid, upgrade to proceed normally Upgrading core rpms... This will take a few minutes, please wait. Currently installed Windows NAC Agent version is 4.9.1.5. Do you want to change the Windows NAC Agent to version 4.9.2.7 (y/n)? y y Currently installed Mac Agent version is 4.9.1.682. Do you want to change the Mac Agent to version 4.9.2.702 (y/n)? y y Going to upgrade the manager rpm ============================================================ After invoking the upgrade.sh from a perl script, it needs to neglect all the output lines and when "Currently installed Windows NAC Agent version is 4.9.1.5. Do you want to change the Windows NAC Agent to version 4.9.2.7 (y/n)? y" , i need to have an option to enter the user input... HOPE i am clear with my issue.. Thanks in advance, SIN.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found