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

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

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

    Alexander, thanks for the detailed response! I'm new to Perl so all that info was very useful as well as well-detailed.

    David