Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Start a program and get a hold of it's STDOUT and STDIN?

Reply
Thread Tools

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

 
 
Snail
Guest
Posts: n/a
 
      04-08-2005
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.


 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      04-08-2005
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
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      04-08-2005
Snail <(E-Mail Removed)> 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
 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      04-08-2005
Snail <(E-Mail Removed)> 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
 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      04-09-2005
Snail <(E-Mail Removed)> 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
 
Reply With Quote
 
Snail
Guest
Posts: n/a
 
      04-09-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Snail <(E-Mail Removed)> 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?


 
Reply With Quote
 
Snail
Guest
Posts: n/a
 
      04-09-2005
Anno Siegel wrote:
> Snail <(E-Mail Removed)> 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.


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      04-09-2005
Snail <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Snail <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
beginner Q: Kernel#puts, STDOUT, $stdout relation Andreas S Ruby 3 12-09-2006 12:39 AM
Problems redirecting STDOUT (NOT sys.stdout) to a pipe. Elad Python 0 03-19-2006 01:30 PM
Hold key to keep the message box before redirecting to a new page (ASP.NET program) bienwell ASP .Net 1 02-23-2006 05:29 PM
copy stdout fails with permission denied when stdout is redirected brian.mabry.edwards@gmail.com Perl Misc 2 12-07-2005 10:49 PM
Re: hold program execution, cin not sequential? Thomas Matthews C++ 0 07-18-2003 02:44 PM



Advertisments