简体   繁体   中英

Multiple commands on one line with Command Prompt and ADB

I am trying to get an automated Android S-OFF method going in my program, but I can't seem to get two commands to follow each other in the same window. For example, my code right now is:

var process = Process.Start("CMD.exe", "/k adb shell chmod 744 /data/local/tmp/soffbin3");
process.WaitForExit();

However, when I run that, nothing occurs in the window. I tried to have the second command follow the first one like this:

var process = Process.Start("CMD.exe", "/k adb shell & chmod 744 /data/local/tmp/soffbin3");
process.WaitForExit();

However, the inclusion of & makes it so the second command doesn't go until the first command completes, and because "adb shell" isn't really a command that completes, it doesn't do the second command.

It was also suggested to me that I replace the /k with a /c , which may as well work, but the window closes almost instantly after opening that command, and I can't confirm that anything actually happened.

I've tried a few variations to try and get it to work, but nothing has worked so far. Is the answer something simple that I'm missing? I really hope it is.

Thanks in advance for the help!

This command work for me

var process = Process.Start("CMD.exe", @"/k adb pull data/data/com.sales.recorder/databases/SalesRecorder c:\adb");
process.WaitForExit();

You Can use the Verbatim escape for the command to avoid issues with your Literal commands. The @ is a verbatim escape so that the information following it in Double Quotes is run as a literal command.

var process = Process.Start("CMD.exe", @"/k adb shell & chmod 744 /data/local/tmp/soffbin3");
    process.WaitForExit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM