【问题标题】:Running an external program (executable) with parameters in python在 python 中运行带有参数的外部程序(可执行文件)
【发布时间】:2017-09-27 00:29:45
【问题描述】:

我正在尝试自动化命令行程序。

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

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

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

C:\source>ztac debug

如何编写一个 Python 程序来运行这个 ztac.exe 文件,同时将不同的模式作为输入?

【问题讨论】:

    标签: python command-line-arguments


    【解决方案1】:
    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')
    

    【讨论】:

    • 谢谢!这行得通,但是,在运行时我无法运行任何其他代码。有 os.spawn 类型的实现可以帮助我做到这一点吗?
    猜你喜欢
    • 2010-12-21
    • 2013-08-27
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2016-01-25
    相关资源
    最近更新 更多