Why 'os.system' exits with return code 1?

蓝咒 提交于 2020-01-06 19:43:12

问题


I want to execute some adb commands from python script. But when i executed the following line

os.system('adb devices')

The cmd returns with 1 instead of 0. I also tried executing

os.popen('adb devices').read()

I am getting empty string. Please help me to solve this. Note: I tried the same commands from command window and it was working fine. I also added the path of adb.exe to windows PATH environment variable.


回答1:


According to Windows docs, you've got 1, because there was an error on your command.

Maybe use subprocess could be a better approach.

import subprocess

subprocess.check_output(
    "adb devices", 
    stderr=subprocess.STDOUT,
    shell=True)


来源:https://stackoverflow.com/questions/25807062/why-os-system-exits-with-return-code-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!