in reply to Re: Can Perl read another terminals STDOUT?
in thread Can Perl read another terminals STDOUT?

Your idea looks promising. As I understand it, the fd/1 is somewhat like a pipe?

I however could not figure out how I was supposed to get to that data stream.

I wrote a perl script that incremented by 1 each second indefinently in a terminal and then went to another terminal and ran the following script:

#!/usr/bin/perl #Get PID of process to monitor print ("PID: "); $fd=<>; print ("$fd\n"); open(FD, "<&=$fd"); @array = <FD>; close(FD); print ("@array\n");


Contents of @array is blank. So I do not think I am understanding how to access that stream.

Replies are listed 'Best First'.
Re^3: Can Perl read another terminals STDOUT?
by zentara (Cardinal) on Apr 19, 2014 at 10:39 UTC
    I believe it is a bit more complicated than just using @array = <FD>, because it is an ongoing stream until the program exits or closes it's stdout. You probably will need to use a select loop on the filedescriptor, or somehow attach to the output.

    If you google for duping stdout linux there are some good links.

    If you figure it out, please let us know. You may have to launch your watched program with a tee tapping off the stdout to another filedescriptor, which you can then read. Good luck.

    P.S. This is not the best way to solve your problem, only a novel way. Using IPC to run the program, is way easier.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh