Goondude
Goondude

Reputation: 101

How to pause cmd before it close?

This is my code

System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
proc.FileName = @"cmd.exe";
proc.Arguments = "/C "+ "ipconfig" ;
System.Diagnostics.Process.Start(proc);

when I run this code , Cmd run and shut down so quickly . How to pause it ?

THANKS A LOT :)

Upvotes: 6

Views: 8172

Answers (2)

Riv
Riv

Reputation: 1859

Specify the K parameter instead of C

From Microsoft documentation:

/c : Carries out the command specified by string and then stops.

/k : Carries out the command specified by string and continues.

proc.Arguments = "/K "+ "ipconfig" ;

more info: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

Upvotes: 6

keyboardP
keyboardP

Reputation: 69362

Use /K instead of /C.

proc.Arguments = "/K " + "ipconfig";

You can see a list of command line switches here

/C Run Command and then terminate

/K Run Command and then return to the CMD prompt. This is useful for testing, to examine variables

Upvotes: 4

Related Questions