python调用subprocess报No such file or directory

时间:2022-08-29 14:32:19

 File "./t1.py", line 11, in <module>
oproc=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
File "/usr/local/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

python调用subprocess报No such file or directory的错误

一开始以为是没有类库

但是对应的类库是存在的

后来仔细看看才发现问题所在

cmd="/usr/local/redis/bin/redis-cli -h "+sys.argv[1]+" -p "+sys.argv[2]
oProc = subprocess.Popen(cmd)

Popen调用的命令是数组的,然后自己写成字符串了

用法用的串了

和commands.getoutput的用法想当然以为一样了