Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause cmd before it close?

Tags:

c#

cmd

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

like image 792
Goondude Avatar asked Jul 12 '13 10:07

Goondude


People also ask

How do I pause cmd execution?

Execution of a batch script can also be paused by pressing CTRL-S (or the Pause|Break key) on the keyboard, this also works for pausing a single command such as a long DIR /s listing.

What is the pause command?

The pause command is used within a computer batch file. It allows the computer to pause the currently running batch file until the user presses any key.

What does @echo off do?

The ECHO-OFF command suppresses echoing for the terminal attached to a specified process. The ECHO-ON command restores input echoing for a specified process. These commands are frequently used in Procs.


2 Answers

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

like image 76
Riv Avatar answered Oct 07 '22 02:10

Riv


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

like image 39
keyboardP Avatar answered Oct 07 '22 03:10

keyboardP