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". ;-)

In reply to Re^3: CGI script: How to run batch file in command window? by afoken
in thread CGI script: How to run batch file in command window? by sirstruck

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.