So I have the following code, the problem is that it exits before all the child processes (sort/gzip) are done. How can I instruct Perl to wait for all the descendent processes ?
#!/usr/bin/perl
use strict;
use warnings;
sub systemBash {
my $cmd = shift;
my @args = ( "bash", "-c", $cmd );
print "command ".$cmd."\n";
system(@args);
if($? != 0){
die "Command ".Dumper(@args)." failed";
}
}
print "start";
systemBash("yes |head -n 1000000|awk '{print rand()}' > >(sort |gzip -9 -c > /dev/null)");
print "done";
I wrote the following hideous code to solve this problem: