uWSGI + Python 子进程不执行 shell 命令

uWSGI + Python subprocess does not execute shell command

uwsgi + Python 子进程

大家好,

我正在尝试 运行 使用 Python 子进程模块在 shell 中执行一个简单的命令,在我输入之前一切正常 顶部的uwsgi。我也用 flask 作为 web 框架。

这里是非常简化的部分代码

if request.method == 'POST':  

            testquery = subprocess.run( "ifconfig", shell=True,stdout=subprocess.PIPE,universal_newlines=True )
            whoisresults=whoisquery.stdout
            print(whoisresults)

我收到以下错误:/bin/sh: 1: ifconfig: 未找到

我用 Python virtual evn 运行s 的完整路径替换了 "ifconfig"。

testquery = subprocess.run( "/home/net/netools/netoolsenv/bin ifconfig", shell=True,stdout=subprocess.PIPE,universal_newlines=True )
            whoisresults=whoisquery.stdout
            print(whoisresults)

但还是不行,只是错误不同 - /bin/sh: 1: /home/net/netools/netoolsenv/bin: Permission denied

谁能请教我应该往哪个方向挖?我是初学者。

I was getting following error : /bin/sh: 1: ifconfig: not found

uWSGI守护进程通常运行作为另一个用户,而这个用户没有PATH设置。使用 ifconfig.

的完整绝对路径

要查找工具的完整路径,请使用 which,例如运行 在您的终端上执行此命令:

$ which ifconfig
/usr/bin/ifconfig

并在 Python 脚本中使用 ifconfig 的完整路径。

testquery = subprocess.run( "/usr/bin/ifconfig", shell=True,stdout=subprocess.PIPE,universal_newlines=True )