我有一个PHP脚本,我在命令行中调用,如下所示:
$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] [--] [args...]
php [options] -r [--] [args...]
php [options] [-B ] -R [-E ] [--] [args...]
php [options] [-B ] -F [-E ] [--] [args...]
php [options] -- [args...]
php [options] -a
edit2:我改变了参数的顺序并且它有效:
[“php”,“php / script / path”,“ – f”,“ – user”,“X”,“ – title”,X,file]
解决方法:
由于文档混乱,这是一个混乱的解释.
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:
call()的签名是:
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
你希望你的CL参数都在一个列表中 – 就像Jakob提供的那样.这是call()的第一个参数.
标签:python,php,process,subprocess
来源: https://codeday.me/bug/20190826/1727554.html