weird behavior with open and pipe



Hi,

I'm still tuning the run()-function of my Command class (see some older
postings of mine, if you like).

I'm using

open($fh_child,"-|");

to fork and to open a pipe to the child, which then exec's a system command.
The parent uses

my @output = <$fh_child>;
close($fh_child);

to receive the output. Here is the problem:

If the childs executes a certain system command and the system command gets
killed externally (by a watchdog), sometimes the parent doesn't receive any
output! Yes, I'm sure, that the system command has written something to std
out before it got killed.

The weird thing is, that if I execute something like

<test.sh>
#!/bin/bash
echo "this is a test"
sleep 10
</test.sh>

and if I kill the process after say 5 seconds, the parent indeed receives
the line "this is a test"!

Obviously it must be some difference in the binaries/system commands. Any
idea, what could be the reason for this difference? Is there a possible
workaround?

I already tried

while ( my $line = <$fh_child> )
{
push ( @{$this->{output}}, $line );
#print "X " . $line;
}

without success...

Cheers,

- Moritz
.



Relevant Pages

  • Re: weird behavior with open and pipe
    ... > to fork and to open a pipe to the child, which then exec's a system command. ... > killed externally, sometimes the parent doesn't receive any ... A shell script is a bad approximation for a single process, ...
    (comp.lang.perl.misc)
  • Re: Cannot get exec syntax correct
    ... then run a system command against each file. ... > # define SAS command string ... > # glob files specified on the command line ...
    (comp.lang.perl.misc)
  • Re: error with system() command: Resource temporarily unavailable
    ... >> the system command. ... >> the same command runs fine on the shell prompt. ... I usually get the "Resource ... Our C program is calling a c++ exe. ...
    (comp.unix.aix)
  • Re: error on simple system command
    ... error on simple system command ... I am trying to use this two line script. ...
    (perl.beginners)
  • Re: help chdir UNC path ( newbie )
    ... is a feature of CMD.EXE and has nothing to do with Perl). ... > Also CMD.EXE will interpret your command as a request to run a program ... the string doesn't get passed to the system command. ...
    (comp.lang.perl.misc)