Python Popen - how to execute commands in nested s

2019-09-16 04:16发布

"I have an issue executing commands in nested adb sub shell in python. executing "command_two" in adb shell opens a sub console in command line (and the console waits for input). how do i execute commands (give input to the console) in that console using the python.

Code:

     R = subprocess.Popen('adb shell', stdin=subprocess.PIPE)
     R.communicate('command_one\ncommand_two\n)

1条回答
我命由我不由天
2楼-- · 2019-09-16 04:37

Please try this:

import time

R = subprocess.Popen('adb shell', shell=True, stdin=subprocess.PIPE)
R.communicate('command_one\n')
time.sleep(2)
R.communicate('command_two\n')
查看更多
登录 后发表回答