call python 'D:\chan.bat'
"set of python statements is stored in notepad and saved as .bat extension. how to run these statements in python.what can be the syntax?"
call python 'D:\chan.bat'
"set of python statements is stored in notepad and saved as .bat extension. how to run these statements in python.what can be the syntax?"
I think this is usually done using the subprocess module:
from subprocess import call
call("D:\chan.bat")
However a normal call doesn't give you back much information. You might need the power of a Popen object:
from subprocess import Popen
Popen("D:\chan.bat")
Edit: You might need to take out the single quotes for this to work.
"'D:\chan.bat'" -> "D:\chan.bat"
If you don't need to interact with the script, wouldn't this work?
import os
os.system("d:\\chan.bat")
I have no Windows box to test it.
Here is what I try on Mac OS
Dinh-Phams-MacBook-Pro:tmp dinhpham$ cat > t.bat
print "abc"
Dinh-Phams-MacBook-Pro:tmp dinhpham$
Dinh-Phams-MacBook-Pro:tmp dinhpham$ python t.bat
abc
Python interpreter does not care about .py extension
If you want to load .bat file as Python module, just use
imp.load_source(path_to_file)
Command can be passed to python as follows:
[avasal@avasal]$ python -c "print 'a' + 'b'"
ab
[avasal@avasal]$
In python --help
you can see, -c cmd : program passed in as string (terminates option list)
, In your batch file, you can make use of this option.