Oct-15-2020, 08:50 AM
Hi,
I am trying to launch a batch file in windows with some arguments from a different directory.
Well its working with
call, as its a straight forward way.
But i want to use
in order to have better control of result.
If i use command
Please let me know what i am missing
I am trying to launch a batch file in windows with some arguments from a different directory.
Well its working with
1 |
os.system |
But i want to use
1 |
subprocess.call |
If i use command
Quote: test.bat -file_arg=drawings/mydrawings.cfgit works, but through python program its gives the error.
Please let me know what i am missing
Output:C:\Users\Projects>C:\Python27\python.exe fp_subprocess.py
CWD: C:\Users\Projects
BAT DIR C:\\MyWork\\Temp\\
script DIR test.bat -file=drawings/mydrawings.cfg
Traceback (most recent call last):
File "fp_subprocess.py", line 28, in <module>
if True == launch_BAT():
File "fp_subprocess.py", line 14, in launch_BAT
subprocess.call(["test.bat"+" -file="+TESTCFG_PATH])
File "C:\Python27\lib\subprocess.py", line 172, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 394, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 644, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def launch_BAT(): TESTBAT_PATH = b 'C:\\MyWork\\Temp\\' TESTCFG_PATH = b 'drawings/mydrawings.cfg' # also tried 'drawings\\mydrawings.cfg' print "CWD:" , os.getcwd() os.chdir(TESTBAT_PATH) print "BAT DIR" , os.getcwd() print "script DIR" , "test.bat" + " -file=" + TESTCFG_PATH print subprocess.call([ "test.bat" + " -file=" + TESTCFG_PATH]) if __name__ = = "__main__" : if True = = launch_BAT(): print "**launch_BAT Successful**" else : print "**launch_BAT UnSuccessful**" |