Both the pybat.bat and pybat.py need to be able to write to the directory that they are located in. Pybat uses 32-bit exit codes, so Windows NT or later is required. You must have the Python 2.4 or later installed.
Although PyBat does have measures to deal with concurrency issues, a multi-threaded Python script should not call a batch file through PyBat because any environment variable changes made by the script in between calling and returning from the pybat.callbat()
function will be overwritten by the environment variables in the batch file.
callbat()
function. Remember that if the batch file's filepath has spaces, it must be enclosed in double-quotes.
import pybat
pybat.callbat('foobar.bat arg1 arg2')
pybat.callbat('"C:\\Program Files\\barfoo.bat" arg1 arg2')
The return value of callbat() is the exit code of the batch file that was run.
call pybat.bat foobar.py arg1 arg2
call pybat.bat "c:\program files\foobar.py" arg1 arg2
The value of %ERRORLEVEL% is set to the exit code of the Python script.
execfile()
function to run other scripts. However, if you must share environment variables and pass the command-line arguments, use Pybat's callpy()
function.callpy()
with the script name and command-line arguments.import pybat
pybat.callpy('foobar.py arg1 arg2')