in reply to perl and windows batch

IMHO, the suggestions put forward thus far, whilst returning the status code back to the calling script, don't appear to address leonidlm's interest in the output from the called batch script - so why not just use backticks. That way, you gain access to the return code (via $?) and the output (via the return from the backtick invocation) e.g.

my $output = `batch_file args`; die "Gone horribly wrong - $?" if $?; # or ... my @output = `batch_file args`; die "Gone horribly wrong - $?" if $?;

.oO(Unless, of course, Windoze sees fit to not return the status code from the batch script, in which case...)

my $output = `batch_file args && exit /b ERRORLEVEL`; die "Gone horribly wrong - $?" if $?; # or ... my @output = `batch_file args && exit /b ERRORLEVEL`; die "Gone horribly wrong - $?" if $?;

,or something similar, may suffice ... unless I'm missing something obvious?!

Sits back and awaits flames, errm, constructive observations ;-)

HTH ,

At last, a user level that overstates my experience :-))

Replies are listed 'Best First'.
Re^2: perl and windows batch
by BrowserUk (Patriarch) on Jul 31, 2008 at 13:06 UTC
      Actually, I found that when I used exit /b in the batch file, I was not getting the return code in my perl. Once I stripped the /b I did.

        Executed from within a batch file, /b sets the %errorlevel% environment variable and exits the batch file, rather than exit cmd.exe and return the value as it process exit code.

        Outside a batch file, (ie. on the command line), /b is a non-op.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.