0

"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)
Wheel60
  • 19
  • 1
  • 11
  • You can try to divide commands to 3 calls of `communicate` and insert pause between them and try to add `shell=True` parameter for `Popen` – Roman Mindlin Oct 06 '17 at 08:40
  • do you mean: R.communicate('command_one'') R.communicate('command_two') R.communicate('command_three) and How do i add Pause in between them. @RomanMindlin – Wheel60 Oct 06 '17 at 14:38

1 Answers1

0

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')
Roman Mindlin
  • 852
  • 1
  • 8
  • 12