2024-09-29 01:29:41 发布
网友
此代码直接在CLI中工作正常:
xmllint --xpath '//Entities[contains(ExpirationDate, '2015')]' app/sftp/file.xml > test.xml
现在,我需要在Python环境中执行相同的命令。这就是我要做的:
这是错误,我正在同一位置运行文件和命令:
OSError: [Errno 2] No such file or directory
如果与派生进程无关,则可以使用os.system()。在
os.system()
但是,如果您真的想使用subprocess.call和流重定向,则必须像下面这样使用它:
subprocess.call
with open('myfile', 'w') as outfile: subprocess.call(["xmllint", " xpath", "//Entities[contains(ExpirationDate, '2015')]", "app/sftp/file.xml"], stdout=outfile)
请注意,subprocess.call将程序名及其参数作为字符串列表,这可能是问题所在
如果与派生进程无关,则可以使用
os.system()
。在但是,如果您真的想使用
subprocess.call
和流重定向,则必须像下面这样使用它:请注意,
subprocess.call
将程序名及其参数作为字符串列表,这可能是问题所在相关问题 更多 >
编程相关推荐