我遇到了子进程模块的问题。我正在尝试在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(我不想要)解决,或者因为问题是由字符串而不是列表参数引起的。
谢谢!
如果您只是尝试从脚本中的提示运行命令,为什么不使用类似的东西
import os
os.system("your command")
你应该能够像它一样运行它
os.system("hrun SomeAction LogFile")