Running a DOS command through C # just opens the cmd window

I tried to execute the command through C #, but when I run the following code, a simple cmd window opens. The code:

string command = string.Format(@"adb install C:\Users\Mohit\Programming\Android_Workspace\{0}\bin\{0}.apk", appName); ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe"); cmdsi.Arguments = command; Process cmd = Process.Start(cmdsi); 

What could be wrong? I am sure the syntax is right.

+4
source share
1 answer

You need to add the / c argument in front of your command.

The / c argument tells the processor command to open, start the specified, then close it,

 string command = string.Format(@"/c adb install C:\Users\Mohit\Programming\Android_Workspace\{0}\bin\{0}.apk", appName); ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe"); cmdsi.Arguments = command; Process cmd = Process.Start(cmdsi); 

A complete list of arguments can be found in the documentation for cmd .

+14
source

Source: https://habr.com/ru/post/1305332/


All Articles