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



我对子进程模块有问题。我正在尝试在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"one_answers" someaction"是字符串,log_file_name是字符串变量。我发现了其他问题,并且大多数(如果不是全部)都用shell = true解决(我不想要),或者是因为问题是由于字符串而不是列表参数引起的。

谢谢!

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

之类的东西
import os
os.system("your command")

您应该能够像

一样运行它
os.system("hrun SomeAction LogFile")

相关内容

最新更新