0

原始代码在这里

import subprocess as sp

cmd = ["adb","push","file","/mnt/sdcard/file"]
mysp = sp.popen(cmd, env={'ADB_TRACE':'adb'}, stdout=sp.PIPE, stderr=sp.PIPE)
stdout,stderr = mysp.communicate()

if mysp.returncode != 0:
    print stderr
else:
    print stdout

没有env={'ADB_TRACE':'adb'}.

用 env 变量执行任何命令adb,我得到一个错误:

ADB server didn't ACK
* failed to start daemon *
error: cannot connect to daemon

杀死 adb 服务器后似乎不起作用

整个输出在这里

操作系统:win7

4

1 回答 1

1

我怀疑 adb 还需要其他环境变量(例如$HOME)。您应该克隆现有环境并添加ADB_TRACE到其中。

import os
new_env = os.environ.copy()
new_env['ADB_TRACE'] = 'adb'

# sp.popen()

从文档:

If env is not None, it must be a mapping that defines the environment variables
for the new process; these are used instead of inheriting the current process’
environment, which is the default behavior.

编辑:

看来,这与环境本身无关。相反,如果ADB_TRACE设置了 adb 服务器,则会损坏。尝试在没有ADB_TRACE.

于 2013-02-10T11:46:13.550 回答