all. I am trying to use python 2.7.1 to run batch files based on what a user enters at the input prompt. The problem I m having is the batch files do not run. I have been able to get a specific batch file to run from python if it is called from main() but cannot get python to select the file based on the input value. My code is:
from subprocess import Popen
def results():
Popen("results.txt")
selection()
def buildinga():
Popen("5463.bat")
results()
def base():
Popen("base.bat")
results()
def selection():
print "This tool will check the device status for the specified building."
print "Type exit to quit the program."
selection.c = input("Please enter the device number: ")
if selection.c == "001":
base()
if selection.c == "5463":
buildinga()
if selection.c == "exit":
exit()
def main():
selection()
main()
我可以操作单一批量档案的方式是:
from subprocess import Popen
def batchwriter():
Popen("make.bat")
def main():
batchwriter()
main()
这样,我就无法选择哪份批量档案,而只有具体文件。 任何帮助都会受到高度赞赏。
我试图在评论中表明这一点,但不能。 原材料正在发挥作用。 批量卷宗正在运行,结果档案显示也出现错误。 错误似乎没有影响功能,因为结果正确。 我正在取得以下产出:
This tool will check the device status for the specified building.
Type exit to quit the program.
Please enter the device number: 5463
Traceback (most recent call last):
File "M:cstatct.py", line 37, in <module>
main()
File "M:cstatct.py", line 34, in main
selection()
File "M:cstatct.py", line 26, in selection
buildinga()
File "M:cstatct.py", line 10, in buildinga
results()
File "M:cstatct.py", line 5, in results
Popen("results.txt")
File "C:UtilitiesPythonlibsubprocess.py", line 672, in __init__
errread, errwrite)
File "C:UtilitiesPythonlibsubprocess.py", line 882, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
M:cstat>[ 12:11:36.63] 5463 is ONLINE