file .bat code example
Example 1: bat stop if call command fails
The ERRORLEVEL environment variable holds the latest return value:
IF %ERRORLEVEL% NEQ 0 (
echo "Previous command execution failed."
exit %ERRORLEVEL%
)
Example 2: what is a windows batch file
@ECHO OFF
ECHO Congratulations! Your first batch file executed successfully.
PAUSE
Example 3: how to run bat file without effect main code
import subprocess
from subprocess import Popen
import time
from multiprocessing import Process,freeze_support
def run_batfile(name='world'):
subprocess.call(["launch_pg.bat"])
if __name__ == '__main__':
# freeze_support()
p = Process(target=run_batfile)
p.start()
# p.join()
count = 0
while True:
count+=1
print(count)
time.sleep(1)