Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Getting Call-Response Behavior with Expect

by zentara (Archbishop)
on Sep 23, 2010 at 10:49 UTC ( #861505=note: print w/ replies, xml ) Need Help??


in reply to Getting Call-Response Behavior with Expect

You may be able to use IPC::Open2 or IPC:Open3 to simplify your code.

For example, try running this:

#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use IO::Select; my $pid = open3(\*WRITE, \*READ,\*ERROR,"/bin/bash"); my $sel = new IO::Select(); $sel->add(\*READ); $sel->add(\*ERROR); my($error,$answer)=('',''); while(1){ print "Enter command\n"; chomp(my $query = <STDIN>); #send query to bash print WRITE "$query\n"; foreach my $h ($sel->can_read) { my $buf = ''; if ($h eq \*ERROR) { sysread(ERROR,$buf,4096); if($buf){print "ERROR-> $buf\n"} } else { sysread(READ,$buf,4096); if($buf){print "$query = $buf\n"} } } } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: Getting Call-Response Behavior with Expect
Download Code
Re^2: Getting Call-Response Behavior with Expect
by gnosti (Friar) on Sep 23, 2010 at 15:19 UTC
    Zentara,

    That's helpful snippet. Just from running that code with the target CL app, I see I wasn't distinguishing between output that came via STDERR and STDOUT in my Expect example.

    I read about IPC::Open2/3 before, and briefly gandered IPC::Run, so I don't know what I got waylaid by Expect.

    I guess I expected something more... Also, the 'select' call is something new to me. Worth learning about.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://861505]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-02 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls