• 13
• 16
• 27
• 9
• 9

# [SOLVED]How to not close command window? C#

This topic is 2566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have code in c# that runs a .cmd file at some point in the program. Below is just an example of my code, but in my program there is some important information that user need to view in command window before it closes. Right now, the command windows closes automatically as soon as the commands are done. But I want to make it so the user closes the window manually after all the commands are done. Thanks!
 String commandFile = "c:\\tempCopy.cmd"; StreamWriter SW; SW = File.CreateText(commandFile); SW.WriteLine("C:"); SW.WriteLine("cd C:\\"); SW.WriteLine("copy C:\\file.txt C:\\anotherfile.txt"); SW.Close(); Process cmd = new Process(); cmd.StartInfo.FileName = commandFile; cmd.Start(); cmd.WaitForExit(); File.Delete(commandFile); 

update: just used a "pause" at the end of command.