ActiveState Powered by ActiveState

ActiveState Community


Running Perl in a WinXP Command Line Batch File

Posted by noahsark on 2008-02-12 18:33

Hi, I wrote a perl script and want to run it in a WinXP command line batch file. The reason why I am doing this is that I have to call a program immediately in order to accomplish some tasks.

My problem is that I want to conditionally run the program after the perl script, i.e.: if the perl script generates error, the program should not be run.

My batch file is really as simple as this.

@echo off
perl -x -S script.pl %1
program.exe %1

As you can see, I want to cover the error case. If a user does not input one argument, my perl script will print usage information, no problem for this. However, the program.exe should not run in this case, I don't know how to do this.

It is probably not a program about perl. Is there any way that a perl program can return its complete code back to the system? Or is there a standard way for doing this?

Many thanks.

MarcZ | Fri, 2008-02-15 07:24

in your batch file you need to check for the return value passed back from the script.

REM check for return value from script:
if errorlevel 0 ECHO script ran OK
if errorlevel 1 ECHO error occured in script1

in your perl script, exit(0) means ok, exit(1) means error.
die results in exit(1).

-->