开发者

Running DOS command through C# just opens blank cmd window

开发者 https://www.devze.com 2022-12-24 04:19 出处:网络
I was trying to execute a command through C#, but when I run the following code, a blank cmd window just opens up. The code:

I was trying to execute a command through C#, but when I run the following code, a blank cmd window just opens up. 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.


You need to add the /c argument before your command.

The /c argument tells the command processor to open, run the specified command, then close when it's done

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);

For a complete list of arguments please refer to the documentation for cmd.

0

精彩评论

暂无评论...
验证码 换一张
取 消