adblib
adblib copied to clipboard
Get STDOUT and STDERR separately, and exit code of command
@tananaev @cgutman is it possible? Everything else I need works fine so far up to Android 10.
I think this is possible because the adb command line tool seems to send the output to the right stream.
Eg:
>adb shell asdf > NUL
/system/bin/sh: asdf: not found
>adb shell echo Hello > NUL
>
But not sure how to do it at the code level
I think this is possible because the
adbcommand line tool seems to send the output to the right stream.
Yes definitely. ADB server (and client) writes to STDOUT and STDERR separately, both in USB and tcpip mode. adbd uses shell protocol to communicate separate out/err and exit code to ADB server. Here are some details: https://android.googlesource.com/platform/system/core/+/refs/tags/android-11.0.0_r1/adb/daemon/shell_service.cpp#17. I'm not sure how much work is needed to implement this in ADBLib.
I just did some quick testing on the emulators, and it looks like shell protocol is only available in devices that are running Android 7.0 or higher. Looks like you can detect whether it's supported by running adb features:
>adb features
cmd
shell_v2
shell_v2 means shell protocol is supported by the Android device
I just did some quick testing on the emulators, and it looks like shell protocol is only available in devices that are running Android 7.0 or higher.
Hmm you are correct. Shell protocol was added in Android 7: https://android.googlesource.com/platform/system/core/+/0955c66b226db7a7f34613f834f7b0a145fd407d
But even targeting Android 7+, it covers 73.7% of active Android devices, as per today's Play Store stats. Not a bad deal, I think.