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.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; }
In reply to Re: Have a perl script launch another script or program, then write to that script's STDIN
by aitap
in thread Have a perl script launch another script or program, then write to that script's STDIN
by xtpu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |