Start a program and get a hold of it's STDOUT and STDIN?

Discussion in 'Perl Misc' started by Snail, Apr 8, 2005.

  1. Snail

    Snail Guest

    Hello. I am trying to write a logging program to wrap around a server
    program that we need that doesn't have logging capabilities of it's own.
    Normally, one would just redirect it on the command line:

    ../server 2>&1 logfile.log

    But this doesn't have any dating what so ever and it can get hard to
    read as it grows.

    My goal is to start the program from my program and get both it's
    STDOUT/ERR and STDIN, that way my program can see live Output as it
    comes in from the server and also respond to certain events (the server
    accepts console commands when it is normally run in the foreground, so
    it can be fully interactive, accepting command via STDIN normally.

    I've been search all over (perldoc, google, etc) and all I could find
    was examples of getting STDIN or STDOUT (using pipes) but not both at
    the same time. Further mode, I need this to be in real time (when the
    server spits out something to STDOUT/ERR I want my program to
    immediately get this, and then process it (add a line to the log file,
    perform some processing if a certain event occurs, such has a new
    connection, etc.)

    Thank for any help.
    Snail, Apr 8, 2005
    #1
    1. Advertising

  2. Snail wrote:
    > Hello. I am trying to write a logging program to wrap around a server
    > program that we need that doesn't have logging capabilities of it's own.
    > Normally, one would just redirect it on the command line:
    >
    > ./server 2>&1 logfile.log
    >
    > But this doesn't have any dating what so ever and it can get hard to
    > read as it grows.
    >
    > My goal is to start the program from my program and get both it's
    > STDOUT/ERR and STDIN, that way my program can see live Output as it
    > comes in from the server and also respond to certain events (the server
    > accepts console commands when it is normally run in the foreground, so
    > it can be fully interactive, accepting command via STDIN normally.
    >
    > I've been search all over (perldoc, google, etc) and all I could find
    > was examples of getting STDIN or STDOUT (using pipes) but not both at
    > the same time. Further mode, I need this to be in real time (when the
    > server spits out something to STDOUT/ERR I want my program to
    > immediately get this, and then process it (add a line to the log file,
    > perform some processing if a certain event occurs, such has a new
    > connection, etc.)


    perldoc -q STDERR


    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Apr 8, 2005
    #2
    1. Advertising

  3. Snail

    Anno Siegel Guest

    Snail <> wrote in comp.lang.perl.misc:
    > Hello. I am trying to write a logging program to wrap around a server
    > program that we need that doesn't have logging capabilities of it's own.
    > Normally, one would just redirect it on the command line:
    >
    > ./server 2>&1 logfile.log
    >
    > But this doesn't have any dating what so ever and it can get hard to
    > read as it grows.
    >
    > My goal is to start the program from my program and get both it's
    > STDOUT/ERR and STDIN, that way my program can see live Output as it
    > comes in from the server and also respond to certain events (the server
    > accepts console commands when it is normally run in the foreground, so
    > it can be fully interactive, accepting command via STDIN normally.
    >
    > I've been search all over (perldoc, google, etc) and all I could find
    > was examples of getting STDIN or STDOUT (using pipes) but not both at
    > the same time. Further mode, I need this to be in real time (when the
    > server spits out something to STDOUT/ERR I want my program to
    > immediately get this, and then process it (add a line to the log file,
    > perform some processing if a certain event occurs, such has a new
    > connection, etc.)


    perldoc IPC::Open2. If that doesn't cut it, see Expect.pm on CPAN.

    Anno
    Anno Siegel, Apr 8, 2005
    #3
  4. Snail

    Guest

    Snail <> wrote:
    > Hello. I am trying to write a logging program to wrap around a server
    > program that we need that doesn't have logging capabilities of it's own.
    > Normally, one would just redirect it on the command line:


    > ./server 2>&1 logfile.log


    > But this doesn't have any dating what so ever and it can get hard to
    > read as it grows.


    > I've been search all over (perldoc, google, etc) and all I could find
    > was examples of getting STDIN or STDOUT (using pipes) but not both at
    > the same time. Further mode, I need this to be in real time (when the
    > server spits out something to STDOUT/ERR I want my program to
    > immediately get this, and then process it (add a line to the log file,
    > perform some processing if a certain event occurs, such has a new
    > connection, etc.)


    % server 2>&1 | wrapper_prog

    Axel
    , Apr 9, 2005
    #4
  5. Snail

    Guest

    Snail <> wrote:
    > Hello. I am trying to write a logging program to wrap around a server
    > program that we need that doesn't have logging capabilities of it's own.
    > Normally, one would just redirect it on the command line:


    > ./server 2>&1 logfile.log


    > But this doesn't have any dating what so ever and it can get hard to
    > read as it grows.
    >
    > My goal is to start the program from my program and get both it's
    > STDOUT/ERR and STDIN, that way my program can see live Output as it
    > comes in from the server and also respond to certain events (the server
    > accepts console commands when it is normally run in the foreground, so
    > it can be fully interactive, accepting command via STDIN normally.


    Does the wrapper program actually need to process any commands before
    they are passed to the server? If not...

    $ ./server 2>&1 | wrapper_prog

    Axel
    , Apr 9, 2005
    #5
  6. Snail

    Snail Guest

    wrote:
    > Snail <> wrote:
    >> Hello. I am trying to write a logging program to wrap around a server
    >> program that we need that doesn't have logging capabilities of it's
    >> own. Normally, one would just redirect it on the command line:

    >
    >> ./server 2>&1 logfile.log

    >
    >> But this doesn't have any dating what so ever and it can get hard to
    >> read as it grows.
    >>
    >> My goal is to start the program from my program and get both it's
    >> STDOUT/ERR and STDIN, that way my program can see live Output as it
    >> comes in from the server and also respond to certain events (the
    >> server accepts console commands when it is normally run in the
    >> foreground, so it can be fully interactive, accepting command via
    >> STDIN normally.

    >
    > Does the wrapper program actually need to process any commands before
    > they are passed to the server? If not...
    >
    > $ ./server 2>&1 | wrapper_prog


    No, my wrapper needs to process OUTPUT coming FROM the server
    (STDOUT/ERR of server.) I also want my wrapper be able to SEND commands
    TO the server (STDIN os server.)

    Would IPC::Open3 be good for this? And using IO::Select for seeing
    whether OUT or ERR has data coming from the server? Is this a good
    approach?
    Snail, Apr 9, 2005
    #6
  7. Snail

    Snail Guest

    Anno Siegel wrote:
    > Snail <> wrote in comp.lang.perl.misc:
    >> Hello. I am trying to write a logging program to wrap around a server
    >> program that we need that doesn't have logging capabilities of it's
    >> own. Normally, one would just redirect it on the command line:
    >>
    >> ./server 2>&1 logfile.log
    >>
    >> But this doesn't have any dating what so ever and it can get hard to
    >> read as it grows.
    >>
    >> My goal is to start the program from my program and get both it's
    >> STDOUT/ERR and STDIN, that way my program can see live Output as it
    >> comes in from the server and also respond to certain events (the
    >> server accepts console commands when it is normally run in the
    >> foreground, so it can be fully interactive, accepting command via
    >> STDIN normally.
    >>
    >> I've been search all over (perldoc, google, etc) and all I could find
    >> was examples of getting STDIN or STDOUT (using pipes) but not both at
    >> the same time. Further mode, I need this to be in real time (when the
    >> server spits out something to STDOUT/ERR I want my program to
    >> immediately get this, and then process it (add a line to the log
    >> file, perform some processing if a certain event occurs, such has a
    >> new connection, etc.)

    >
    > perldoc IPC::Open2. If that doesn't cut it, see Expect.pm on CPAN.


    Sorry if I wasn't clear. I need to be able ot get output (from STDOUT of
    server) from server in real time, and sometimes I may want to send a
    command to the server (to STDIN of server) from my wrapper.

    Thanks.
    Snail, Apr 9, 2005
    #7
  8. Snail

    Anno Siegel Guest

    Snail <> wrote in comp.lang.perl.misc:
    > Anno Siegel wrote:
    > > Snail <> wrote in comp.lang.perl.misc:
    > >> Hello. I am trying to write a logging program to wrap around a server
    > >> program that we need that doesn't have logging capabilities of it's
    > >> own. Normally, one would just redirect it on the command line:


    [...]

    > > perldoc IPC::Open2. If that doesn't cut it, see Expect.pm on CPAN.

    >
    > Sorry if I wasn't clear. I need to be able ot get output (from STDOUT of
    > server) from server in real time, and sometimes I may want to send a
    > command to the server (to STDIN of server) from my wrapper.


    You made that clear enough. Those modules can help you in doing it.

    Anno
    Anno Siegel, Apr 9, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    5
    Views:
    548
    Stuart MacMartin
    Aug 29, 2005
  2. Ben
    Replies:
    2
    Views:
    1,322
    jacob navia
    Aug 29, 2009
  3. Jon Hawkins

    stdin stdout -ing my program

    Jon Hawkins, Aug 12, 2007, in forum: Ruby
    Replies:
    5
    Views:
    114
    Alex Gutteridge
    Aug 14, 2007
  4. Terry Cooper
    Replies:
    7
    Views:
    418
    Janos Sebok
    Jun 9, 2009
  5. Stefano Sabatini
    Replies:
    6
    Views:
    280
    Stefano Sabatini
    Jul 29, 2007
Loading...

Share This Page