import subprocess
obj = subprocess.Popen(['notepad.exe','text.txt'], shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
print(obj.stderr.read().decode('gbk'))
obj = subprocess.Popen('python', shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
obj.stdin.write('print(6+7)'.encode('utf-8'))
info,err = obj.communicate()
print(info.decode('gbk'))
obj = subprocess.Popen(['adb', 'shell'], shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
obj.stdin.write('ls\n'.encode('utf-8'))
obj.stdin.write('exit\n'.encode('utf-8'))
info,err = obj.communicate()
print(info.decode('gbk'))
print(err.decode('gbk'))
cmds = [
"cd data",
'cd data',
"ls",
"exit",
]
obj = subprocess.Popen("adb shell", shell= True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
info = obj.communicate(("\n".join(cmds) + "\n").encode('utf-8'));
for item in info:
if item:
print(item.decode('gbk'))
import chardet
obj = subprocess.Popen("adb logcat", shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
for item in iter(obj.stdout.readline,'b'):
encode_type = chardet.detect(item)
if encode_type['encoding'] == 'utf-8':
print(item.decode('utf-8'))
elif encode_type['encoding'] == 'Windows-1252':
print(item.decode('Windows-1252'))
else:
print(item.decode('gbk'))