ENV

2013-02-10 7 views
0

으로는 popen()를 사용하는 경우 작업 "ADB 장치"를 얻는 방법을 원래의 코드는 env={'ADB_TRACE':'adb'}없이 잘 작동 hereENV

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 

입니다.

간부 모든 명령에 대한 adb ENV 변수로, 나는 오류가 있어요 :

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

는 ADB 서버를 한 후 작업을 죽이지 것을

전체 출력은 here

OS : win7

+0

'ADB_TRACE'를 설정하고 명령 행에서'adb'를 실행하면 작동합니까? – Vlad

답변

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. 

편집 :

것 같다,는 envoronment 자체에 대한 아니다. ADB_TRACE이 설정되면 adb 서버가 손상됩니다. ADB_TRACE이없는 환경에서 미리 서버를 시작하십시오.

+0

작동합니다. 많이 thx : D – tastypear

+0

답변을 수락 해 주시기 바랍니다 :-) –