in reply to Open3 and bad gut feeling
Arg..
I had thought I had overcome the problem of executing large command lines by writing the command line into script that is executed. However, even though the created script runs fine directly from the command line, I have found that if I run it through the attached sub and the line to be executed execeeds 357 characters I 'hang' (MSwin32 - 2000). Additionally I have attempted to implement IO::Handle and IO::Select but apparently not in an effective way. (If it is indeed some type of a buffering problem). I lost all day yesterday to this code and hope someone can pinpoint my ignorance, or am I just exceeding the limitations of open3?
Here's the relevant code. (note: I pushed all the logging to a separate module)
# RETURNS: %OSexec = ( stdout => $stdout, stderr => $stderr pid => $pi +d ) sub OSexecute { my $execute = $_[0]; my $stdin = IO::Select->new(); # not sure what difference <&STDIN and \*STDIN have $stdin->add("\*STDIN"); my $din = IO::Handle->new(); $stdin->add($din); my $stdout = IO::Select->new(); $stdout->add(\*STDOUT); my $dout = IO::Handle->new(); $stdout->add($dout); my $stderr = IO::Select->new(); $stderr->add(\*STDERR); my $derr = IO::Handle->new(); $stderr->add($derr); my ( $pid, $val, $out, $err ); my ( @stdin, @stdout, @stderr ); my $debug = "false"; #$debug = "true"; if ( $debug =~ /true/i ) { print "OSify::Execute::OSexecute::\$execute = $execute\n"; } # Here is the actual execution eval { print "Executing $execute\n"; $pid = open3( $din, $dout, $derr, $execute ); print "Waiting for pidout\n"; # waitpid waits for the proces to exit # $val could be used as a means to determine status # while waiting if that functionality becomes needed. $val = waitpid(-1,0); #wait's for process to complete # Process the results # Standard Out my $line; my @stdout = <$dout>; foreach $line (@stdout) { chomp($line); $out = $out . $line; } if ( ! $out ) { $out = 1; } # Standard Error @stderr = <$derr>; foreach $line ( @stderr ) { chomp($line); $err = $err . $line; } if ( ! $err ) { $err = 1; } }; $@ && die "OSify::OSexecute died upon execution of\n$execute\nWith +$@"; # Question remains what activity qualifies as draining the buffer? $din->flush(); $din->close; $dout->flush(); $dout->close; $derr->flush(); $derr->close; my %OSexec = ( stdout => $out, stderr => $err, pid => $pid, ); print "Execute Finished with @{[%OSexec]}\n"; return %OSexec; }
Here's a very typical script it will execute. The antcall.bat doesn't even have to exist to duplicate the problem.
E:\\cccharv\\JDK\\Release\\scripts\\antcall.bat -logfile E:\\cccharv\\ +testApp\\testVer\\Unit_Test\\antscripts\\build\\logs\\20020219-082532 +_Ant_build_testApp.txt -buildfile E:\\cccharv\\testApp\\testVer\\Unit +_Test\\antscripts\\buildTESTAPP.xml compileTESTAPPClean buildTESTAPPJ +ar buildTESTAPPWar buildClientControllerEJB buildTESTAPPSessionEJB bu +ildTESTAPPEar
Getting rid of the last three characters eliminates the hang
coreolyn
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Open3 and bad gut feeling : 357 char STDIN limit?
by coreolyn (Parson) on Feb 19, 2002 at 18:45 UTC | |
|
Re: Re: Open3 and bad gut feeling : Finally
by coreolyn (Parson) on Feb 19, 2002 at 22:20 UTC | |
by ikegami (Patriarch) on Sep 15, 2004 at 00:30 UTC | |
by coreolyn (Parson) on Sep 15, 2004 at 12:01 UTC |