Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: problem with forking

by chime (Friar)
on Jul 06, 2004 at 10:39 UTC ( [id://372059]=note: print w/replies, xml ) Need Help??


in reply to Re^2: problem with forking
in thread problem with forking

Another way to run applications instead of using exec or fork is to use expect; from the Expect module.
This is very useful for unruly programs that cause your Perl to hang.
I have also used open3 instead of fork / exec but am now currently converting open3 to expect. #Even though it only is available for linux it might be useful to you.

Everything I know is here
http://search.cpan.org/dist/Expect.pm/

Some code that uses this

use Expect; my ($program_name, $login, $sourcefile) = @_; #spawn program_name using perl expect module my $exp = Expect->spawn($program_name,$login) or die "Cannot spawn $program_name $login: $!\n"; #turn off output of results from stdout $exp->log_stdout(0); # wait for program_name to initialise $exp->expect(600,[ qr/Program ready to start/]); # send appropriate command to program_name $exp->send("run program_name $report_name $output_format $source +file \n"); # Wait for report to run or generate an error $exp->expect(600,[ qr/Error/i, sub { my $self = shift; $self->send("quit\n"); print ("perl_program.pl has found an error: + $_ \n"); exp_continue; }], [ qr/Report run successful./i, sub { my $self = shift; $self->send("quit\n"); exp_continue; }]); }

Log In?
Username:
Password:

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

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

    No recent polls found