$PHP importTextFile.PHP --user "X" --title "name" notice_X.txt
我想在python脚本中使用该文件.我试过了 :
for file in os.listdir("."):
subprocess.call(["PHP", "-f", "importTextFile.PHP"], "--user=X", "--title="'%s' % name, file)
File "./pageFromFile.py", line 21, in main
subprocess.call(["PHP", "-f","importTextFile.PHP"], "--user=Bot", "--title="'%s' % nom, fichier)
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 629, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
edit1:谢谢它的工作原理,但是我遇到了args的问题,因为出现了Usage消息:
Usage: PHP [options] [-f] <file> [--] [args...]
PHP [options] -r <code> [--] [args...]
PHP [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
PHP [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
PHP [options] -- [args...]
PHP [options] -a
edit2:我改变了参数的顺序并且它有效:
[“PHP”,“PHP / script / path”,“ – f”,“ – user”,“X”,“ – title”,X,file]
解决方法:
由于文档混乱,这是一个混乱的解释.
来自:http://docs.python.org/library/subprocess.html#frequently-used-arguments
To support a wide variety of use cases, the Popen constructor (and the
convenience functions) accept a large number of optional arguments.
For most typical use cases, many of these arguments can be safely left
at their default values. The arguments that are most commonly needed
are:
来自:http://docs.python.org/library/subprocess.html#subprocess.call
call()的签名是:
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
你希望你的CL参数都在一个列表中 – 就像Jakob提供的那样.这是call()的第一个参数.
其他位置参数对应于类subprocess.Popen(http://docs.python.org/library/subprocess.html#subprocess.Popen)的初始化参数. bufsize恰好是其中之一.