Python Popen在Linux上工作,但在Windows上没有
我想在Linux和Windows上运行相同的代码。下面的代码在Linux上工作,但在Windows上不起作用!
#!/usr/bin/env python3
import subprocess
def runcmd(cmd,show=True):
print("cmd:" + cmd)
try:
p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
retval = p.communicate()[0]
print(retval)
return retval.decode('utf-8')
except:
print("cmd error:" + cmd)
pass
return ""
def main():
runcmd("adb shell 'find /data/ -type f ! -empty'")
return
if __name__ == "__main__":
main()
Windows10的输出:
cmd:adb shell 'find /data/ -type f ! -empty'
b'/system/bin/sh: find /data/ -type f ! -empty: inaccessible or not found\r\n'
I would like to run the same code on linux and windows. below code works on linux but not on windows!
#!/usr/bin/env python3
import subprocess
def runcmd(cmd,show=True):
print("cmd:" + cmd)
try:
p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
retval = p.communicate()[0]
print(retval)
return retval.decode('utf-8')
except:
print("cmd error:" + cmd)
pass
return ""
def main():
runcmd("adb shell 'find /data/ -type f ! -empty'")
return
if __name__ == "__main__":
main()
The output from windows10:
cmd:adb shell 'find /data/ -type f ! -empty'
b'/system/bin/sh: find /data/ -type f ! -empty: inaccessible or not found\r\n'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将整个ADB Shell命令放入一个参数中。使用:
您可能在Linux和Windows上具有不同版本的
adb
。 文档提到在Android平台中处理的参数在Android Platform中的处理方式发生了变化-Tools 23。Don't put the entire adb shell command in a single argument. Use:
You may have different versions of
adb
on Linux and Windows. The documentation mentions that the way the arguments are processed changed in Android Platform-Tools 23.