I try to develop c# app to install apk to android phone with adb shell but I'm beginner for both. I cant send command to cmd.
void getDevices()
{
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(@"cmd.exe");
p = Process.Start(startInfo);
p.StandardInput.WriteLine(@"cd " + @"C:\Users\user\Desktop\adb\");
// String output = p.StandardOutput.ReadToEnd();
}
There are three options:
cmd.exe
when you start it cmd.exe
after it has started Pass the commands into cmd.exe
when you start it
To pass commands to cmd.exe
you can use the -k
or -c
parameters of cmd.exe
.
For example, this will start cmd.exe
, display the logged on user and then terminate the cmd.exe
process:
cmd.exe /c "whoami"
Look at this page or Google for more examples.
Send the commands to cmd.exe
after it has started
The alternative is to first start cmd.exe
and later send commands to it. There are quite a few questions about that around already, but there generally seem two approaches:
I'm not sure if they'll work with cmd.exe
.
Writing a batch file or PowerShell script
The more common approach to automating cmd.exe
is to write a batch file or PowerShell script. You may also want to consider these options.
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.