FAQ
perl version
------------
v5.6.0 built for MS-Win32-x86-multi-threa
with patch ActivePerl Build 618


Question
--------
When I manually issue a certain command in DOS,
the exit code is 1:
cmd badarg
(ERROR MSG)
echo %errorlevel%
1
>

But when I run this short perl program,

exitcheck.pl:
$x = system("cmd badarg");
print "exit code: $x \n";

the exit code returned
by the 'system' command is 0:
perl exitcheck.pl
(ERROR MSG)
exit code: 0
>


This does not happen with all commands; just with some.
The command in question is actually a batch file:
cmd.bat
and I am wondering if this has something to do with the problem.
The cmd.bat file runs a java application.

I am finding that I cannot rely on the 'system' call to accurately
report exit codes on NT (I have not had this problem on Unix or Linux).
Is there some other method of checking the exit code of a command on WinNT?


Thank you,
Janet Hare
Sun Microsystems
I

Search Discussions

  • John Peacock at Feb 13, 2002 at 7:39 pm

    Janet Hare wrote:
    perl version
    ------------
    v5.6.0 built for MS-Win32-x86-multi-threa
    with patch ActivePerl Build 618
    [Insert standard upgrade statement here]

    You may want to upgrade to the latest ActivePerl and see if that
    helps. 618 is rather old.

    [deletia]

    This does not happen with all commands; just with some.
    The command in question is actually a batch file:
    cmd.bat
    and I am wondering if this has something to do with the problem.
    The cmd.bat file runs a java application.
    Yes that is probably the problem. The system() command is reporting
    the error code in the program that *it* ran (i.e. the .BAT file) which
    was a success; the batch file itself catches the error code but does
    not pass it on (AFAIK). Is there any way you could call the offending
    program directly from Perl?

    HTH
    John

    --
    John Peacock
    Director of Information Research and Technology
    Rowman & Littlefield Publishing Group
    4720 Boston Way
    Lanham, MD 20706
    301-459-3366 x.5010
    fax 301-429-5747
  • Michael G Schwern at Feb 13, 2002 at 7:44 pm

    On Wed, Feb 13, 2002 at 11:25:17AM -0800, Janet Hare wrote:
    perl version
    ------------
    v5.6.0 built for MS-Win32-x86-multi-threa
    with patch ActivePerl Build 618
    You'll probably want to be upgrading.

    Question
    --------
    When I manually issue a certain command in DOS,
    the exit code is 1:
    cmd badarg
    (ERROR MSG)
    echo %errorlevel% 1
    But when I run this short perl program,

    exitcheck.pl:
    $x = system("cmd badarg");
    print "exit code: $x \n";

    the exit code returned
    by the 'system' command is 0:
    perl exitcheck.pl
    (ERROR MSG)
    exit code: 0

    This does not happen with all commands; just with some.
    The command in question is actually a batch file:
    cmd.bat
    and I am wondering if this has something to do with the problem.
    The cmd.bat file runs a java application.

    I am finding that I cannot rely on the 'system' call to accurately
    report exit codes on NT (I have not had this problem on Unix or Linux).
    Is there some other method of checking the exit code of a command on WinNT?
    I presume that "(ERROR MSG)" above comes from inside cmd.bat and not
    because DOS can't find or run cmd.bat? Its possible that cmd.bat is
    exiting normally, it just doesn't know what to do with 'badarg' and is
    printing an error/warning.

    You might want to try writing a short C program to run "cmd badarg"
    and check the exit value. Otherwise, I think you can get away with
    this simple batch file:

    cmd badarg
    if errorlevel 0 echo "cmd exited with zero"
    if errorlevel 1 echo "cmd exited with non-zero"

    I think...

    Either way, find some way independent of Perl to run 'cmd badarg' and
    check the exit code.


    --

    Michael G. Schwern <schwern@pobox.com> http://www.pobox.com/~schwern/
    Perl Quality Assurance <perl-qa@perl.org> Kwalitee Is Job One
    stretch your colon out,
    put some effort into it,
    and shit through that paste.
    -- japhy

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedFeb 13, '02 at 7:25p
activeFeb 13, '02 at 7:44p
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase