简体   繁体   中英

How to run a command in C# Console Application using switches in the command?

I am trying to run a command in my C# console app but keeps failing with

'w:\start' is not recognized as an internal or external command, operable program or batch file.

The drive gets mapped successfully and can run the command with just using @"/CW:\Setup.exe" but as you can see in the below code there are switches now:

System.Diagnostics.Process.Start("cmd.exe", @"/c w:\start /wait setup.exe /auto upgrade /NoReboot /DynamicUpdate disable /showoobe None /Telemetry Disable").WaitForExit();

And when I run the app it gives me the above error? Am I missing something here?

Thanks

Assuming setup.exe is on W: drive, you can write:

System.Diagnostics.Process.Start("cmd.exe", @"/c start /wait ""Some Title"" w:\setup.exe /auto upgrade /NoReboot /DynamicUpdate disable /showoobe None /Telemetry Disable").WaitForExit();

Indeed, using the start command line command with options you need to specify a title for the console window, between start options and the file to execute and its own 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.

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