Hi, I have to run an external program but the program does not termination on some conditions, e.g, ping, will not exit unless you specify -c or some other circumstances.
Now I what I want to do is: my @array; die "Cannot fork myprog" unless (defined my $pid = fork) if ($pid==0){ open MYPROG, "myprog |" or die "Cant run myprog"; my $timeout = 0; while (<MYPROG>){ exit(0) if $timeout == 3; push @array, $_; sleep 1; $timeout++; } waitpid($pid, 0); print "@array\n"; The problem with the code above is that @array goes back to its initial state after exiting the child. No contents are printed. I even tried references but it didn't work as well. If I don't use fork, I the way I would kill the process is by doing a call to pkill. With fork, it would be much easier with exit. However the output of external program gets discarded. Can you think of any workaround for this? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/