Popen shell 命令和空格问题
Popen shell commands and problems with spaces
我有这段代码,它 运行 是用户为 adb 输入的任何命令,例如,用户输入单词 'devices' 并且 'adb.exe devices' 将 运行并打印出设备列表。
这适用于 'devices' 但每当发出更复杂的命令时,例如带有空格的命令,'shell pm path com.myapp.app' 它就会失败。
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
在将 .GetValue() 中的字符串放入 params 并 运行 放入 Popen 之前,我是否需要对其进行一些格式化或处理?
subprocess.Popen
和 shell=True 采用完整的命令字符串,而不是列表。
params = str(buildpath)+"\adb.exe"+c_arg #c_arg is a string of arguments.
我有这段代码,它 运行 是用户为 adb 输入的任何命令,例如,用户输入单词 'devices' 并且 'adb.exe devices' 将 运行并打印出设备列表。 这适用于 'devices' 但每当发出更复杂的命令时,例如带有空格的命令,'shell pm path com.myapp.app' 它就会失败。
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
在将 .GetValue() 中的字符串放入 params 并 运行 放入 Popen 之前,我是否需要对其进行一些格式化或处理?
subprocess.Popen
和 shell=True 采用完整的命令字符串,而不是列表。
params = str(buildpath)+"\adb.exe"+c_arg #c_arg is a string of arguments.