in reply to Re^2: CGI script: How to run batch file in command window?
in thread CGI script: How to run batch file in command window?
As long as every program started by run.bat just writes to STDOUT and STDERR, you can even use a "pipe open" and read the output directly, without messing with temporary files and without fighting the race conditions that come with them:
open my $pipe,'run.bat |' or die "Ooops: $!"; while (my $line=<$pipe>) { print $line; # <-- stupid example } close $pipe;
Note that this example catches only STDOUT, not STDERR. If you want both in ONE stream (that may become very hard to "unmix"), use output redirection:
open my $pipe,'run.bat 2>&1 |' or die "Ooops: $!"; # ...
If you want only STDERR, use that, plus get rid of STDOUT (write to the null device, i.e. NUL on DOS/Win, /dev/null on Unix):
open my $pipe,'run.bat 2>&1 >nul |' or die "Ooops: $!"; # ...
If you want both streams separately, use IPC::Open3 or similar.
Also note that you probably don't need the wrapping batch file, you can also start the java runtime executable directly, typically java.exe -jar jarfile.jar arg1 arg2:
open my $pipe,'java.exe -jar jarfile.jar arg1 arg2 |' or die "Ooops: $ +!"; # ...
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: CGI script: How to run batch file in command window?
by sirstruck (Initiate) on May 21, 2010 at 17:52 UTC |