Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Have a perl script launch another script or program, then write to that script's STDIN

by aitap (Curate)
on Jan 06, 2014 at 08:01 UTC ( [id://1069469]=note: print w/replies, xml ) Need Help??


in reply to Have a perl script launch another script or program, then write to that script's STDIN

It should be possible using IPC::Open2. Expect and IPC::Run also can help. For example, this is a "backticks on steroids" sub from one of my projects:
use IPC::Open2 'open2'; sub backtick { my ($in, @cmd) = @_; # $in is a string to pass to STDIN, # @cmd is a command to run my $pid = open2(my $stdout, my $stdin, @cmd); # first we write to stdin print {$stdin} $in if defined $in; close $stdin; # then we read the response my $out = do { local $/; <$stdout> }; # then we wait for the program to die waitpid $pid, 0; # beware of deadlocks! die "$cmd[0] returned $? / error $!\n" if $?; return $out; }
You'll need to be careful not to end up in situations where both your script and the script you are controlling via STDIN wait for input from each other. Buffering can also be a problem. More information: Bidirectional Communication with Another Process.
  • Comment on Re: Have a perl script launch another script or program, then write to that script's STDIN
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found