fork download
  1. use strict;
  2. use warnings;
  3. use POSIX qw(:sys_wait_h);
  4.  
  5. my $arg = "...";
  6. my $pid;
  7. my $reader;
  8. my $r_bits = '';
  9. if ($pid = open $reader, '-|'){
  10. vec($r_bits, fileno($reader), 1) = 1;
  11. # ...
  12. }
  13. else {
  14. defined $pid or die "cannot open pipe";
  15. exec('perl', 'foo.pl', $arg);
  16. die "cannot exec command";
  17. }
  18.  
  19. while(1) {
  20. my $wait_pid = waitpid $pid, WNOHANG;
  21. my $found = select(my $rout = $r_bits, undef, undef, 0);
  22. if ($found && vec($rout, fileno($reader), 1)) {
  23. print do{ local $/; readline($reader) };
  24. }
  25. if ($wait_pid > 0) {
  26. # ...
  27. last;
  28. }
  29.  
  30. ...
  31. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty