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

问题描述 投票:0回答:1

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

谢谢!

python subprocess
1个回答
0
投票

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

import os
os.system("your command")

你应该能够像它一样运行它

os.system("hrun SomeAction LogFile")
© www.soinside.com 2019 - 2024. All rights reserved.