【发布时间】:2019-03-08 01:35:59
【问题描述】:
我遇到了子流程模块的问题。我正在尝试在 Python 中运行终端命令,该命令在终端中运行良好。命令是:
hrun SomeAction LogFile
我尝试了多种选择,包括 call()、run()、check_output() 和 Popen()。无论我使用哪种方法,我都会收到错误:
FileNotFoundError: [Errno 2] No such file or directory: 'hrun': 'hrun'
我的代码是:
output = Popen(["hrun", "SomeAction", log_file_name], stdout=PIPE, stderr=PIPE)
其中“hrun”和“SomeAction”是字符串,log_file_name 是字符串变量。 我发现了其他 SO 问题,并且大多数(如果不是全部)都通过 shell=True (我不想要)解决,或者因为问题是由于字符串而不是列表参数引起的。
谢谢!
【问题讨论】:
-
这意味着
hrun命令不在您的PATH环境变量中。
标签: python subprocess