danmcb has asked for the wisdom of the Perl Monks concerning the following question:
I have a file where I run a shell command into a pipe. It looks like this:
#!/usr/bin/perl -w use strict; use Net::SSH::Expect; use TestExt; use Data::Dumper; package Test; sub run { my $cmd = 'ls -al'; my $pid = open OUT, "$cmd |" or die "cannot fork: $!"; print "running \"$cmd\" (pid = $pid) ... \n"; my @a = <OUT>; print "closing ... \n"; close OUT or die "cannot close: $! $?"; print @a; } package main; my @a = Test->run(); print @a;
The reason for the package Test will become clear in a moment. Now, I do the same thing but with the run method in an external file. here it is:
package TestExt; sub run { my $cmd = 'ls -al'; my $pid = open OUT, "$cmd |" or die "cannot fork: $!"; print "running \"$cmd\" (pid = $pid) ... \n"; my @a = <OUT>; print "closing ... \n"; close OUT or die "cannot close: $! $?"; print @a; } 1;
Now change the call to "TestExt->run()" and things stop working. When "CLOSE" is called, you get "cannot close: No child processes -1" as an error.
Now, if I remove the "use Net::SSH::Expect", everything works fine, both ways.
This is on a CentOS system, with a standard perl 5.8.8. It seems like quite an odd interaction, (why would having the code in an external module affect things?) and I suspect that it is a bug in Net::SSH::Expect. But if anyone here has any ideas about this, or can verify it on other systems, I'd be very interested to hear them before I file a report. Of course, there could as well be some silly error in there that I have not spotted, too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: odd interaction of Net::SSH::Expect and open
by salva (Canon) on Oct 16, 2007 at 13:32 UTC | |
|
Re: odd interaction of Net::SSH::Expect and open
by almut (Canon) on Oct 16, 2007 at 14:42 UTC | |
by danmcb (Monk) on Oct 17, 2007 at 11:14 UTC | |
by bnegrao (Initiate) on Apr 19, 2008 at 15:41 UTC |