Python子进程错误:Popen,调用,运行“没有这样的文件或目录:错误

时间:2019-03-08 01:35:59

标签: python subprocess

我在子流程模块上遇到了问题。我正在尝试在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(我不想要)解决了,或者因为问题是由于字符串而不是列表参数引起的。

谢谢!

1 个答案:

答案 0 :(得分:0)

如果您只是想从脚本中的提示符运行命令,为什么不使用类似的

import os
os.system("your command")

您应该能够像这样运行它

os.system("hrun SomeAction LogFile")