Popen无法处理在Shell中运行的命令 [英] Popen is no able to process a command that runs in shell

查看:336
本文介绍了Popen无法处理在Shell中运行的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了以前关于同一论点的问题,但我真的还没有弄清楚.

I have already read the previous questions posted on the same argument but I really haven't figured it out yet.

我正在尝试运行一个在命令行中不会出现问题的命令:

I am trying to run a command that works without issues from the command line :

xyz@klm:~/python-remoteWorkspace/PyLogParser/src:18:43>ush -o PPP -p PRD -n log 'pwd'
6:43PM PPP:prd:lgsprdppp:/ama/log/PRD/ppp

但是当我在python中做同样的事情时,我总是会出错:

but when I do the same in python I always get errors :

stringa = Popen(["ush -o PPP -p PRD -n log 'pwd'"], stdout=PIPE, stdin=PIPE).communicate()[0]

这是错误.

Traceback (most recent call last):   File "getStatData.py", line 134, in <module>
    retrieveListOfFiles(infoToRetList)   File "getStatData.py", line 120, in retrieveListOfFiles
    stringa = Popen(["ush -o PPP -p PRD -n log 'pwd'"], stdout=PIPE, stdin=PIPE).communicate()[0]   File "/opt/python-2.6-64/lib/python2.6/subprocess.py", line 595, in __init__
    errread, errwrite)   File "/opt/python-2.6-64/lib/python2.6/subprocess.py", line 1092, in _execute_child
    raise child_exception OSError: [Errno 2] No such file or directory

我也尝试过类似的解决方案

I've tried also different solutions like

stringa = Popen(["ush", "-o", "PPP", "-p" "PRD", "-n", "log", '"pwd"'], stdout=PIPE, stdin=PIPE).communicate()[0]

,但似乎没有任何效果.我还尝试过绝对的努力,但没有采取任何措施. 有人可以解释一下我在做什么错吗?

but nothing seems to work. I have also tried to put the absolute path to ush but nothing... Can somebody please explain me what am I doing wrong ?

谢谢,上午.

当我这样做的时候,我发生了一件奇怪的事情

EDIT : I have a strange thing happening, when I do

which ush

我知道

ush: aliased to nocorrect /projects/aaaaaaa/local/ush/latest/ush.py

但是为什么它能正常工作?

But why is it working then ???

!!!谢谢大家的回答!!!

!!! Thank you all for the answers !!!

推荐答案

如果系统上的ush是别名,则popen将不起作用. popen需要一个可执行文件作为第一个参数:绝对路径或PATH中内容的名称.

If ush on your system is an alias, popen won't work. popen requires an executable file as the first parameter: either an absolute path or the name of something that is in your PATH.

这篇关于Popen无法处理在Shell中运行的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆