[Perl] A wierd bug on system interaction

Shlomo Yona shlomo at siftology.com
Sun Mar 31 22:54:26 PST 2002


Amir Abiri wrote:
> 
> Shalom,
> 
> I am having an annoying problem with ``/qx{}/open "CMD |". They all act the
> same in this respect:
> 
> code snippet:
> 
> @lines = `adsl start`
> printf @lines;
> 
> adsl is another perl script that launches pptp and all the rest of the
> things that has to do with connecting to the internet.
> 
> This code hangs. The adsl script, when it finishes it goes zombie, and the
> calling perl script doesn't seem to notice that fact. I get a CHLD signal
> and can process it, but no matter what i do the script keeps hanging on the
> backsticks line.
> 
> The adsl script works just fine by itself, no prblems there. and the same
> code snippet would work with a nother, simpler command. I can't use system()
> and wait() since i need the command's output.
> 
> Any ideas ?

Try something like this to run your commands.


sub run_cmd {
   my ($cmd) = @_;
   my $term_msg = "$0 will now terminate!\n";
   open(IN, "$cmd |") 
	or die("Can't fork: $!\n$term_msg \n line: ";
        while (<IN>) {
                print STDERR $_;
        }
        print STDERR $cmd ."\n";
        close(IN) 
		or die("Cannot close: $!\n$term_msg \n line: " ;
        die ("Problems running |$cmd|\n$term_msg" if ($?!=0);
}


-- 
Shlomo Yona.
Software Engineer.
Siftology Ltd. Israel.
Shlomo.Yona at Siftology.com



More information about the Perl mailing list