reading stdout/stderr using pipes 
Author Message
 reading stdout/stderr using pipes

the basic scenario is i want a perl script to control an interactive
process, feeding input to an application over a pipe, reading the
results of each command back over another pair of pipes, one for
stdout and another for stderr, and repeating this cycle for as long
as desired.

the 2 pipes for stdout/stderr are created using pipe(), then the
open command

        $pid = open(SEND, "|-");

is used to effect the fork and create a pipe for the stdin to the app.
in the child, stdout/stderr from the app are set to the appropriate
pipes, file handles are set to line buffering, and the app is exec'ed.
the parent sends a command to the app, reads results, and repeats.

when there's no error, or if i send stdout and stderr over the same
pipe, everything's hunky-dory.  BUT, when there's both stdout and
stderr coming across separate pipes, things aren't happy.

there are 2 basic problems i'm experiencing:

     1  after a command is issued to the app, i must read any stderr
        before reading the stdout, or the read of stdout will block.
        i have the input separator set to the the app's prompt, so each
        read on this pipe should get all the stdout related to that
        command, and does provided i check and read stderr first.
        when there's no stderr from a command, reading stdout will
        not block.

        a test app gave the same results.  regardless of whether the
        test app wrote to stdout or stderr first, i had to read the
        stderr first, or the read on stdout would block.  might this
        change for different flavors of Unix. (currently using ConvexOS)
        is this a Unix thang?  a Perl thang?  programmer error?

     2  after sending the 'quit' command to the app, the select(mask,
        mask,mask,timeout) i use to check if stderr's pipe is ready to
        be read, returns a count of 1.  at this point, eof() returns a
        1 for this pipe as well, so i can detect there's no more stderr
        to be read, but i would expect select would time out in this
        case, as it does for other commands.

        when calling select, i only set a mask for the first argument,
        and a timeout of 1.5 seconds.  the return is immediate, with
        a return value of 1.  should a file for which eof() is true
        be considered to be ready for reading?

thanks,
-steve
--
  Steven Grotten                                CONVEX Computer Corporation
  SPP Development Software Test                      3000 Waterview Parkway

  phone: 214/497-4045



Sun, 06 Apr 1997 05:12:37 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Directing stderr and stdout to a pipe

2. Distinguishing stdout and stderr on a pipe

3. sending stdout and stderr to a pipe in perl

4. pipe, STDOUT, and STDERR

5. how to read stdout AND stderr from a program

6. reading STDERR from a piped process file handle

7. Reading stderr from a pipe?

8. Piping STDERR to /dev/null when using system()

9. Piping in stderr when creating a pipe with the open call

10. Read from STDERR using Expect

11. repost : Read return value from a sql script using piped open

12. read return value from a sql script using piped open

 

 
Powered by phpBB® Forum Software