adb shell running multiple commands from same cmd window

百般思念 提交于 2020-04-30 07:23:07

问题


I am trying to create a Perl script to run set of commands through adb shell.

cmd1 
cmd2 
cmd3 
cmd3(1)

I put all the commands in a text file and ran it like this: adb shell < adb_commands.txt.(reference)

However, I have this one issue where the last command cmd3(1) needs to be executed from within the previous command cmd3.
So cmd3 will be executed and will wait for cmd3(1) to be entered. This is not happening coz as far as i can tell, adb shell is waiting for cmd3 to finish so it can run cmd3(1).

Can someone please advise on how to solve this issue or if there are any alternate ways to do this?

Thanks.


回答1:


Use & not &&

&& run next command only if the previous were successful

& run next command after the previous finish no matter successful or not




回答2:


You can execute multiple commands separated by && operator

adb shell "netcfg && ps && getprop"



回答3:


I don't understand what do you mean by "cmd3(1) needs to be executed from within the previous command cmd3"; the work should be done in the cmd3 function, not in the adb shell. Maybe you could provide a more detailed explanation.

But, in order to execute several commands in one line, you may use adb shell "cmd1;cmd2;cmd3". The && command mentioned by @Rachit is not quite right, because in the case adb shell "netcfg && ps && getprop", command ps will be executed only when netcfg is executed without error raised.



来源:https://stackoverflow.com/questions/30269950/adb-shell-running-multiple-commands-from-same-cmd-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!