Capturing output of a system command 
Author Message
 Capturing output of a system command

I've got a Win32 perl script that calls the sun javac compiler using
the system command. It works great, but I have no way of capturing the
output of that command. So I can't figure out if there are any errors.

I've tried redirecting or piping the output of the javac command, but
the output isn't captured. They must not be using stdout or something.
Any ideas?

Sent via Deja.com
http://www.*-*-*.com/



Fri, 01 Aug 2003 23:02:23 GMT  
 Capturing output of a system command

Quote:

> I've got a Win32 perl script that calls the sun javac compiler using
> the system command. It works great, but I have no way of capturing the
> output of that command. So I can't figure out if there are any errors.

You could always check the return value of the "system" call; and
if that isn't what you want, you could use backticks instead.

Quote:
> I've tried redirecting or piping the output of the javac command, but
> the output isn't captured. They must not be using stdout or something.
> Any ideas?

See

  % perldoc -f system

and the discussion of backticks in

  % man perlop

HTH

Joe Schaefer
--
#include <stdio.h> /* requires gcc and *nix
use strict; system("cc -x c $0") and die $?; open C, "|a.out" or die $! . q*/
main(){char s[32]; remove("a.out"); printf("%s/C hacker\n",fgets(s,32,stdin));
return 0;}/*; print C "Just another Perl"; close C or die $?; #*/



Fri, 01 Aug 2003 23:23:37 GMT  
 Capturing output of a system command
Quote:

> I've got a Win32 perl script that calls the sun javac compiler using
> the system command. It works great, but I have no way of capturing the
> output of that command. So I can't figure out if there are any errors.

[snipped]

try using the backticks to run the command.
ie: $out_command= `program args`;

or you can do something like this

open (YOURCMD, "program args |") or die "can't run program: $!\n";
while(<YOURCMD>)   {

  $cmdout=.$_;

Quote:
}

close(YOURCMD);

I hope this helps

Mothra!



Fri, 01 Aug 2003 23:19:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. capturing output of executed system command

2. Capturing System Command Output with Perl on Windows/Apache

3. Capture output from system command?

4. capturing system command output

5. capturing command line error or output from `<command>`

6. capturing output of FILEHANDLE "| command"

7. capturing output from a remote command (how?)

8. capturing output of piped commands

9. Help with Piped command, capturing output

10. Capture command output into list?

11. help with capturing output of open command

12. How do I capture output from a print command

 

 
Powered by phpBB® Forum Software