Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My script runs a succession of .bat files, each of which is dependent on the success of the one preceeding it, thus I need the exit code of each, however, as they are batch files not general dos cmds each file returns 0 regardless of success or failure.

Replies are listed 'Best First'.
Re: Win32 child process exit values
by bbfu (Curate) on Sep 06, 2001 at 20:30 UTC

    Which Win32 OS are you talking about? I can't say for other OS's for sure, but Win2k (and I believe NT - or not, tye has informed me) has an EXIT command that you can put at the end of a batch file which will cause it to return a status-code.

    In test.bat:

    @rem test.bat @exit 1

    In test.pl:

    #!perl print "The result is: ", system('test.bat'), "\n";

    test.pl will print (remember that the return status is only the high byte):

    The result is: 256

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

(tye)Re: Win32 child process exit values
by tye (Sage) on Sep 07, 2001 at 01:23 UTC

    For WinNT's command.exe, I was able to get a *.bat execution to return a "failed" exit status via: goto non_existant_label_name_here 2>nul and was not able to find any way to get a Win9x cmd *.bat execution to return a "failed" exit status.

            - tye (but my friends call me "Tye")