'cd' command not working in adb shell function call
bfujimoto-dev opened this issue · 5 comments
When using bash terminal on MacOs, I don't have any issue with adb commands; however when using AdbClient in Python 3.7, the 'cd' command does not work, for example: device.shell('cd /system/bin') simple returns ''. Other common commands like ls -la, cp, chmod, etc all work fine in device.shell(). For such a common command as 'cd', I'm wondering if I am missing something?
I've searched extensively on StackOV and others but I found nothing in this regard. Any guidance is much appreciated.
I'm using version 0.3.0.dev0
The cd command should not return anything.
Every time you make a shell, it has a different context. Use commands in the same context, separated by semicolons.
Example:
print(1, device.shell('pwd'))
print(2, device.shell('cd /system/bin; pwd'))
print(3, device.shell('pwd'))
Out:
1 /
2 /system/bin
3 /
Thanks for the feedback, I really had no clue that a new shell is created each time device.shell() is invoked.
I wanted to run multiple shell command in a sequenc like
- cd /system/bin
- Given some delay - 5-sec delay
- ls
In your above solution how to provide a delay between the command and I wanted to see the output also after each step is it possible?
In your above solution how to provide a delay between the command and I wanted to see the output also after each step is it possible?
It seems to me that you cannot simultaneously save the context and get step-by-step output. If the context is more important to you, then use sleep 5
, if step-by-step output is more important, then call the device.shell
several times, and use time.sleep
from python between calls.
For example, in this case, the command output will appear at the same time and only after the last command has finished:
print(device.shell('date; sleep 5; date'))
Tue Apr 20 17:28:12 MSK 2021
Tue Apr 20 17:28:17 MSK 2021
Thanks for your response, but my use case required to run multiple commands in the same context, We have some test applications that I need to launch and provide STDIN to the same context multiple times with delay, and the sleep command won't work inside this application.
That's why I am looking for interactive shell implementation, is it supported? or any other way to implement the same?