Re: Capturing STDOUT of system launched process
Hi, some alternative approaches would be: my $res = `$cmd`; # note that it's not "'" but "`" # $res only stdout, this will puke out stderr or my $res = `$cmd 2>&1`; # redirect stderr to stdout # $res is now both stderr and stdout or my $res = `$cmd 2>/dev/null`; # throw away stderr # $res is only stdout and no errors shown /Jon insomniak wrote: > > Hi, > You can always write STDERR and STDOUT to a temp file then read the contents > of this file back in to your script. > > eg > system (some_command 1>.stdout 2>.stder); > STDOUT is written to .stdout > STDERR is written to .stderr > > Theres is probably a better way than this but I find this the easiest. > Anyone else have any comments? > > regards > Mark Kneen > > - Original Message - > From: "Matthew Blacklow" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, September 27, 2001 12:44 AM > Subject: Capturing STDOUT of system launched process > > > I am writing a script at the moment which among others things creates > > another process using the system call. > > What I need to do is capture the screen output of this process into a > string > > variable so that it can latter be manipulaterd. ie. capture the STDOUT. > > > > Any help, suggestions or sample code would be appreciated. > > > > Thanks, > > Matthew > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing STDOUT of system launched process
Hi, You can always write STDERR and STDOUT to a temp file then read the contents of this file back in to your script. eg system (some_command 1>.stdout 2>.stder); STDOUT is written to .stdout STDERR is written to .stderr Theres is probably a better way than this but I find this the easiest. Anyone else have any comments? regards Mark Kneen - Original Message - From: "Matthew Blacklow" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 27, 2001 12:44 AM Subject: Capturing STDOUT of system launched process > I am writing a script at the moment which among others things creates > another process using the system call. > What I need to do is capture the screen output of this process into a string > variable so that it can latter be manipulaterd. ie. capture the STDOUT. > > Any help, suggestions or sample code would be appreciated. > > Thanks, > Matthew > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing STDOUT of system launched process
> "Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]> said: > Of course, all of these should have error-checking: > > $x = `...` or die "can't run ...: $!"; > > open OUTPUT, "... |" or die "can't run ...: $!"; Don't forget to check the close for errors. If the pipe fails for some reason close returns 0 and $? has the exit value. -- Smoot Carl-Mitchell Consultant -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing STDOUT of system launched process
On Sep 27, Matthew Blacklow said: >What I need to do is capture the screen output of this process into a string >variable so that it can latter be manipulaterd. ie. capture the STDOUT. Several options: # qx() and `` are the same $output = `prog arg1 arg2`; $output = qx(prog arg1 arg2); # get lines of output, not one lone string @output = `prog arg1 arg2`; @output = qx(prog arg1 arg2); # open a pipe, and go line-by-line open OUTPUT, "prog arg1 arg2 |"; while () { ... } close OUTPUT; # or get it all at once open OUTPUT, "prog arg1 arg2 |"; { local $/; # read all the content at once $output = ; } close OUTPUT; Of course, all of these should have error-checking: $x = `...` or die "can't run ...: $!"; open OUTPUT, "... |" or die "can't run ...: $!"; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Capturing STDOUT of system launched process
I am writing a script at the moment which among others things creates another process using the system call. What I need to do is capture the screen output of this process into a string variable so that it can latter be manipulaterd. ie. capture the STDOUT. Any help, suggestions or sample code would be appreciated. Thanks, Matthew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]