How to run more than 1 command inside open?
I have a code below. Here, I am running make $i inside open, but now I want to run more than 1 command here, say make $i; sleep 30; echo abc. How can I do that?
foreach $i (@testCases) {
my $filehandle;
if ( ! (my $pid = open( $filehandle, "make $i 2>&1 |" ) )) {
die( "Failed to start process: $!" );
}
else {
print "Test started\n";
}
}
Just to add the following is not working properly:
if (!($pid = open( my $pipe, "make $i; sleep 30; echo abc |" ))) " {
print "Problem in openeing a filehandle\n";
} else {
print "$pid is pid\n";
my $detailedPs=`tasklist | grep "$pid"`;
chomp ($detailedPs);
print "$detailedPs is detailedPs\n";
}
Here, I am getting $detailedPs as empty. If things would have run correctly, I would have got something in $detailedPs
Preferred:
Short for: (non-Windows)
But note that you have a code injection bug. Fixed:
With IPC::Run:
But you'd be better off avoiding a shell.