Borgme Borgme - 7 months ago 62
Bash Question

Popen shell commands and problems with spaces

I have this code, it runs whatever command the user enters for adb, e,g the user enters the word 'devices' and 'adb.exe devices' will run and print out the device list.
This works fine with 'devices' but whenever a more complex command is issued, such as one with spaces, 'shell pm path' it fails.

c_arg = self.cmdTxt.GetValue() ##gets the user input, a string
params = [toolsDir + '\\adb.exe', c_arg] ##builds the command
p = Popen(params, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ## executes the command
stdout, stderr = p.communicate() ## get output
self.progressBox.AppendText(stdout) # print output of command

Is there some formatting or processing I need to do on the string from .GetValue() before I can put it into params and run it in Popen?


subprocess.Popen with shell=True takes the full command string, not a list.

params = str(buildpath)+"\\adb.exe"+c_arg #c_arg is a string of arguments.