【发布时间】:2016-10-14 14:44:51
【问题描述】:
我有这个代码,它运行用户为 adb 输入的任何命令,例如,用户输入单词“设备”,“adb.exe 设备”将运行并打印出设备列表。 这适用于“设备”,但只要发出更复杂的命令,例如带有空格的命令,“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 中运行之前,是否需要对字符串进行一些格式化或处理?
【问题讨论】:
-
如果您提供命令行作为吃的列表,shell 必须是 False - 默认值,所以只需删除 shell 论据
标签: android python shell wxwidgets