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

S

Snail

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.
 
J

John W. Krahn

Snail said:
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
 
A

Anno Siegel

Snail said:
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
 
A

axel

Snail said:
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
 
A

axel

Snail said:
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
 
S

Snail

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?
 
S

Snail

Anno said:
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.
 
A

Anno Siegel

Snail said:
[...]
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top