Reputation: 227
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
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]
Here the error.
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 ?
Thanks in advance, AM.
EDIT : I have a strange thing happening, when I do
which ush
I get
ush: aliased to nocorrect /projects/aaaaaaa/local/ush/latest/ush.py
But why is it working then ???
!!! Thank you all for the answers !!!
Upvotes: 0
Views: 653
Reputation: 204758
Popen(["ush", "-o", "PPP", "-p", "PRD", "-n", "log", "pwd"])
should be right. The extra quoting around 'pwd'
in the shell command makes it a single argument, but the quotes aren't actually passed along. Since you're already splitting the arguments, leave the extra quotes out.
Apparently (in an update from OP) ush
is a shell alias. Thus, it only expands in the shell; anywhere else, it won't work. Expand it yourself:
Popen(["nocorrect", "/projects/aaaaaaa/local/ush/latest/ush.py",
"-o", "PPP", "-p", "PRD", "-n", "log", "pwd"])
Upvotes: 2
Reputation: 385970
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.
Upvotes: 1