Skip to content

Commit 0c93f4f

Browse files
committed
added adb_commands.StreamingShell
1 parent 89dd297 commit 0c93f4f

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

adb/adb_commands.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ def Shell(self, command, timeout_ms=None):
222222
self.handle, service='shell', command=command,
223223
timeout_ms=timeout_ms)
224224

225+
def StreamingShell(self, command, timeout_ms=None):
226+
"""Run command on the device, yielding each line of output.
227+
228+
Args:
229+
command: the command to run on the target.
230+
timeout_ms: Maximum time to allow the command to run.
231+
232+
Yields:
233+
The responses from the shell command.
234+
"""
235+
return self.protocol_handler.StreamingCommand(
236+
self.handle, service='shell', command=command,
237+
timeout_ms=timeout_ms)
238+
225239
def Logcat(self, options, timeout_ms=None):
226240
"""Run 'shell logcat' and stream the output to stdout."""
227241
return self.protocol_handler.StreamingCommand(

adb_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ def testBigResponseShell(self):
113113
adb_commands = self._Connect(usb)
114114
self.assertEqual(''.join(responses), adb_commands.Shell(command))
115115

116+
def testStreamingResponseShell(self):
117+
command = 'keepin it real big'
118+
# expect multiple lines
119+
120+
responses = ['other stuff, ', 'and some words.']
121+
122+
usb = self._ExpectCommand('shell', command, *responses)
123+
124+
adb_commands = self._Connect(usb)
125+
response_count = 0
126+
for (expected,actual) in zip(responses, adb_commands.StreamingShell(command)):
127+
self.assertEqual(expected, actual)
128+
response_count = response_count + 1
129+
self.assertEqual(len(responses), response_count)
130+
116131
def testReboot(self):
117132
usb = self._ExpectCommand('reboot', '', '')
118133
adb_commands = self._Connect(usb)

0 commit comments

Comments
 (0)