execStream method
Like exec, but for a command that is not supposed to finish: returns a ShellStreamHandle delivering stdout line by line while the command keeps running.
Use it for continuous sampling — a loop reading /proc once a second, a
logcat follow — where exec would either buffer forever or force one
adb process per sample.
command is passed to adb shell as-is. A shell script has to be a
single element, because the host shell is deliberately bypassed
(runInShell: false) and would otherwise re-split it:
final handle = await client.shell().execStream([
'while true; do head -v -n 999 /proc/stat; sleep 1; done',
]);
final subscription = handle.lines.listen(parseLine);
// ...
await subscription.cancel();
await handle.stop();
The device-side command dies with the adb process, so ShellStreamHandle.stop
is all the cleanup there is — nothing is left running on the device.
Implementation
Future<ShellStreamHandle> execStream(
List<String> command, {
bool debug = false,
}) async {
return await ShellStreamHandle.start(_bridge.executor, [
..._connection.arguments,
'shell',
...command,
], debug: debug);
}