Question

I have a POE Perl program forking children.

The children it is forking do logging and interactive telnets into remote devices. POE uses STDOUT to return output back up to the parent process but for some reason it's getting lost (not going to screen or to any files).

I'm theorising that this is because STDOUT is being redirected somewhere - I need to ascertain where.

I have used (-t STDOUT) to identify that the STDOUT of the child is not a TTY.

I have also reset the STDOUT of the child to be that of the parent before the child was called - but this method seems to avoid POE's event handlers and it just dumps the output to parents STDOUT.

Q) How do I identify what the current STDOUT points at so I can find where my data is going

Thanks

Simon

Was it helpful?

Solution 3

This was down to the POE::Filter::Reference StdOut Handler being sent output by the child process that was not in the format it was expecting.

Removed the filter - could then see what it was being sent and this enabled me to rectify the issue.

The issue was the child process was spewing the contents of its subprocesses STDOUT back along the socket connection to the StdOut Handler.

Simon

OTHER TIPS

Would fileno help in this situation? If a child is closing and reopening STDOUT, then fileno(STDOUT) would have a different value in the child than in the parent.

$ perldoc -f fileno
   fileno FILEHANDLE
           Returns the file descriptor for a filehandle, or undefined if
           the filehandle is not open.  This is mainly useful for
           constructing bitmaps for "select" and low-level POSIX tty-
           handling operations.  If FILEHANDLE is an expression, the value
           is taken as an indirect filehandle, generally its name.

           You can use this to find out whether two handles refer to the
           same underlying descriptor:

               if (fileno(THIS) == fileno(THAT)) {
                   print "THIS and THAT are dups\n";
               }

           (Filehandles connected to memory objects via new features of
           "open" may return undefined even though they are open.)

If your forked children are Perl programs too you can "select STDOUT" and set $| to mark it unbuffered right before any logging happens.

Are you certain this isn't a buffering issue? I'm not familiar with POE so I don't know how you'd investigate or correct that, but I suspect it's worth checking, at least.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top