2011-01-27 136 views
4

我在尝试自动化命令行程序。使用python中的参数运行外部程序(可执行文件)

exe文件需要一个参数才能运行。例如:

ztac.exe <mode> (其中模式选项safenormaldebug)。

在调试模式下运行我只需在命令行中键入:

C:\source>ztac debug

我怎样写一个Python程序,而采取不同的模式作为输入来运行这个文件ztac.exe

回答

2
program = 'ztac.exe' 
arguments = ('safe', 'normal', 'debug') 
argument = raw_input('Enter your argument: ') 
if argument in arguments: 
    subprocess.call([program, argument]) 
else: 
    print('Illegal Argument') 
+0

谢谢!然而,这是有效的,但是在运行时我无法运行任何其他代码。有一个os.spawn类型的实现,可以帮助我做到这一点? – user591821 2011-01-27 09:47:33

相关问题