0

I am trying to execute the command below using Popen(shlex.split(cmd)... and Popen(cmd.split(' ')...but running into errors below, how else can I run this command or how to debug this error?

def function_create_cmds(cmd): print cmd #proc = Popen(shlex.split(cmd), shell=True, stdout=PIPE, stderr=PIPE) proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE) (output, error) = proc.communicate() return output,error cmd = "/usr/local/bin/xbs submitproject -notesfile /Users/usernamea/autosubmissionlogs/07162018_133945/milestone/project-375/project-375.plist -version project-1.0.7 /Users/usernamea/wifiroots/project Release" (output,error) = function_create_cmds(cmd) print output print error 

Error:

Popen(cmd.split(' '), INFO: submitproject was unable to locate a submission directory named Popen(shlex.split(cmd) xbs requires a command 
13
  • 1
    Recieve your command as an array, not a string. Commented Jul 17, 2018 at 16:17
  • 1
    cmd as string seems already not good, or else split would have worked. materialize your arguments in a list, don't pass a string. Commented Jul 17, 2018 at 16:18
  • @CharlesDuffy - am taking the cmd as string but using shlex.split(cmd) without shell=Truewhich still doesnt work Commented Jul 17, 2018 at 17:11
  • "doesn't work" doesn't really tell us anything useful. Give us the post-split list, and a working shell command line, and we could tell you something. (Though I advise against using shlex.split(cmd) -- it's significantly worse than an explicit list, as the explicit list will work with filenames with spaces and the like, whereas shlex.split() requires them to be escaped). Commented Jul 17, 2018 at 17:14
  • 1
    So, if you're passing cmd.split(' '), then print(repr(cmd.split(' '))) in your code, and edit the output into your question. If you're using shlex.split(cmd), likewise, edit the output of print(repr(shlex.split(cmd))) into the question. Commented Jul 17, 2018 at 17:16

1 Answer 1

0

Don't use shell=True it needlessy invokes a shell to run your subprocess, thus calling two processes for no benefit.

proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) 

Should work. If it doesn't, please provide the error you're getting in this case.

You could always split the command yourself:

subprocess.Popen([ "/usr/local/bin/xbs", 'submitproject', '-notesfile', '/Users/usernamea/autosubmissionlogs/07162018_133945/milestone/project-375/project-375.plist', '-version', 'project-1.0.7', '/Users/usernamea/wifiroots/project', 'Release', ]) 
Sign up to request clarification or add additional context in comments.

3 Comments

Trying without shell=True just hangs the script ,dont see any error, how else can we debug this?
If you're using shell=True with a list where the first argument isn't a script that refers to its argument list, then every argument but the first is ignored, which... well, completely explains your error message.
removing shell=True actually worked but sometimes one of the command hangs because the executable is waiting on a userprompt ,Is there a way to add a timeout and save the output until the timeout

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.