Issue
trying to figure out how to do this:
command = f"adb -s {i} shell"
proc = Popen(command, stdin=PIPE, stdout=PIPE)
out, err = proc.communicate(f'dumpsys package {app_name} | grep version'.encode('utf-8'))
but in this:
command = f"adb -s {i} shell"
proc = run(command, stdin=PIPE, stdout=PIPE, shell=True)
out, err = run(f'dumpsys package {app_name} | grep version', shell=True, text=True, stdin=proc.stdout )
The idea is to make a command which require input of some kind( for example(entering shell)) and afterwards inserting another command to shell. I've found a way online with communicate, But I wonder how to do it with run() func. Thanks!
Solution
You only need to call run
once -- pass the remote command in the input
argument (and don't use shell=True
in places where you don't need it).
import subprocess, shlex
proc = subprocess.run(['adb', '-s', i, 'shell'],
capture_output=True,
input=f'dumpsys package {shlex.quote(app_name)} | grep version')
shlex.quote
prevents an app name that contains $(...)
, ;
, etc from running unwanted commands on your device.
Answered By - Charles Duffy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.