Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello PerlMonks,

I'm trying to spawn a Perl process via an Expect loop. The idea is that the main program would be sending Perl code to the slave, and have it return stuff on STDOUT, which would be received, parsed and acted upon by the main program. I tried to implement this via Expect, but it seems to be deadlocking. Can someone point out what I'm doing wrong?

I'm using Perl v5.14.1 if that makes a difference.

Thanks much. Pankaj

use Expect; # create a pipe to slave Perl process my $exp = new Expect; $exp->raw_pty(1); $exp->exp_internal(1); $exp->spawn("/usr/bin/perl") or die "Couldn't start Perl: $!\n"; $exp->log_user(0); $exp->log_stdout(0); # attempting to unbuffer the slave Perl's stdout test_ipc ("select STDOUT; \$| = 1;\n"); test_ipc ("print \"Got this\\n\";\n"); # close the pipe $exp->hard_close(); sub test_ipc { my $line = shift @_; # send command to Perl $exp->send ($line); # may receive any number of lines in return (or none) my $done = 1; while ($done) { $exp->expect (1, [qr"\r\n" => sub { print STDOUT $exp->before(). "\n"; exp_ +continue; }] , [timeout => sub { $done = 0; print STDOUT "TIMED OUT\n"; +}] , [eof => sub { $done = 0; print STDOUT "DONE\n"; }] ); } }

In reply to Running Perl in an Expect loop by StoneLeopard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found