如何在Python中使用参数运行应用程序? [英] How to run application with parameters in Python?

查看:414
本文介绍了如何在Python中使用参数运行应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个应用程序(二进制文件)并使用Python代码传递参数。一些参数表示在Python文件处理期间获得的字符串。

I need to run an application (binary file) and pass arguments using a Python code. Some arguments represent strings got during Python file processing.

for i in range ( len ( files ) ) :
    subprocess.call(["test.exe", files[i]]) //How to pass the argument files[i]

谢谢...

更新后的问题:

也许我不理解在Python 3中传递参数。没有参数的代码可以运行

Maybe I do not understand passing arguments in Python 3. A code without parameters runs OK

args = ['test. exe']
subprocess.call(args)

但是带有参数的代码会导致错误:

However the code with parameter causes an error:

args = ['test. exe']
subprocess.call(args, '-f')  //Error

错误:

Error File "C:\Python32\lib\subprocess.py", line 467, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python32\lib\subprocess.py", line 652, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer


推荐答案

args = ['test. exe']
subprocess.call(args, '-f')  //Error

应该是:

args = ['test.exe', '-f']
subprocess.call(args) 

命令行参数应该都在subprocess.call第一个参数的单个列表内。调用的第二个参数是bufsize,它应该是整数(因此,为什么会出现错误)

The command line argument should all be inside a single list for the first parameter of subprocess.call. The second argument to call is bufsize, which is supposed to be an integer (hence why you get the error you do)

这篇关于如何在Python中使用参数运行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆