简体   繁体   English

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

[英]Python subprocess error: Popen, call, run "No such file or directory: error

I'm having issues with the subprocess module. 我在子流程模块上遇到了问题。 I'm trying to run a terminal command in Python, which works perfectly fine in the terminal. 我正在尝试在Python中运行终端命令,该命令在终端中可以正常运行。 The command is: 命令是:

hrun SomeAction LogFile

I've tried a variety of options, including call(), run(), check_output(), and Popen(). 我尝试了各种选项,包括call(),run(),check_output()和Popen()。 No matter which method I use, I get the error: 无论我使用哪种方法,都会出现错误:

FileNotFoundError: [Errno 2] No such file or directory: 'hrun': 'hrun'

My code is: 我的代码是:

    output = Popen(["hrun", "SomeAction", log_file_name], stdout=PIPE, stderr=PIPE)

where "hrun" and "SomeAction" are strings and log_file_name is a string variable. 其中“ hrun”和“ SomeAction”是字符串,而log_file_name是字符串变量。 I found other SO issues and, most (if not all) were resolved with either shell=True (which I dont want), or because the issue was due to a string instead of a list argument. 我发现了其他SO问题,大多数(如果不是全部)都通过shell = True(我不想要)解决了,或者因为问题是由于字符串而不是list参数引起的。

Thanks! 谢谢!

If you are just trying to run a command from a prompt within a script why not use something like 如果您只是尝试从脚本中的提示符运行命令,为什么不使用类似

import os
os.system("your command")

You should be able to just run it like 您应该能够像这样运行它

os.system("hrun SomeAction LogFile")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM