- Self Test
- Calling a Batch File from a Python Script
- Calling a Python Script from a Batch File
- Calling a Python Script from a Python Script
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.
The return value of callbat() is the exit code of the batch file that was run.
pybat.callbat('foobar.bat arg1 arg2')
pybat.callbat('"C:\\Program Files\\barfoo.bat" arg1 arg2')
The value of %ERRORLEVEL% is set to the exit code of the Python script.
call pybat.bat foobar.py arg1 arg2
call pybat.bat "c:\program files\foobar.py" arg1 arg2
execfile()function to run other scripts. However, if you must share environment variables and pass the command-line arguments, use Pybat's
Import the pybat module and call
callpy()with the script name and command-line arguments.
pybat.callpy('foobar.py arg1 arg2')