Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get STDOUT and STDERR separately, and exit code of command #4

Open
mirfatif opened this issue Aug 22, 2020 · 4 comments
Open

Get STDOUT and STDERR separately, and exit code of command #4

mirfatif opened this issue Aug 22, 2020 · 4 comments

Comments

@mirfatif
Copy link

@tananaev @cgutman is it possible? Everything else I need works fine so far up to Android 10.

@mirfatif mirfatif changed the title Get STOUT and STDERR separately, and exit code of command Get STDOUT and STDERR separately, and exit code of command Aug 22, 2020
@sampalmer
Copy link
Contributor

sampalmer commented Nov 18, 2020

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

@mirfatif
Copy link
Author

I think this is possible because the adb command 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.

@sampalmer
Copy link
Contributor

sampalmer commented Nov 22, 2020

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

@mirfatif
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants