Kumar
Kumar

Reputation: 626

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

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.

Upvotes: 0

Views: 7768

Answers (1)

Mauro Baraldi
Mauro Baraldi

Reputation: 6575

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)

Upvotes: 4

Related Questions