in reply to Running perl script from a perl script
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = open3(\*WRITE, \*READ, 0,"success.pl"); #if \*ERROR is false, STDERR is sent to STDOUT #get the answer chomp(my $answer = <READ>); print "query = $answer\n"; waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.
....or run a command interpreter like bash, and print commands to it
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; $|=1; #my $pid=open3(\*IN,\*OUT,\*ERR,'/bin/bash'); my $pid=open3(\*IN,\*OUT,0,'/bin/bash'); # set \*ERR to 0 to send STDERR to STDOUT my $cmd = 'date'; #send cmd to bash print IN "$cmd\n"; my $result = <OUT>; print $result;
|
---|