Reading from a file another process has written 
Author Message
 Reading from a file another process has written

I'm trying to collect STDERR from another process.  The code I have looks
open (STDERR, "+>/tmp/$$.errs") or die "Can't open error temp file: $!\n" ;

[stuff to spawn a child process, wait until it is done]

if ((stat STDERR)[7] > 0)
    print "<p><p><font color='red'><h2>ERRORS</h2><p>\n" ;
    print "Chars in error file: ".(stat STDERR)[7] ;
    print "<pre>" ;
    seek STDERR, 0, 0 ;
    print <STDERR> ;
    print "</PRE>" ;


I put in the 'Chars in error file' to confirm that at that point the file
*DOES* have the right length [and indeed, if I look at it from a separate
telnet session I can read the file right off, and it has exactly the right
stuff in it].  My problem?  The "<STDERR>" never returns _anything_.  I
tried replacing it with "read STDERR, $errs, 1000000" and the read
completes without an error and says "0 bytes read".

It seems that Perl "knows" that my process hasn't written anything to
STDERR and so "knows" that the file length is zero, even though it really
isn't.  Is there some way to convince Perl to look at the file's _real_
length?  I guess I could switch from read->sysread, although I usually
don't like doing that.

For technical reasons, I'd like to be able to have the file "just open" [as
I did there] rather than opening it, feeding it to the child, closing it
[in the parent], and the re-opening it in the parent when the child

Bernie Cosell                     Fantasy Farm Fibers

    -->  Too many people, too few sheep  <--          

Mon, 27 Jan 2003 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Connecting to an Access 7

2. Accessing COM port

3. Having problems writing a tar file.

4. I am having trouble reading in a variable from a file

5. How to read & write to telnet process

6. Reading and writing with a process

7. reading AND writing to processes

8. Open a new process for read AND write

9. write and read to a process at the same time

10. Help!read/write telnet process from perl

11. Reading AND writing to a child process

12. Read/Write running process


Powered by phpBB® Forum Software