Jump to content
  • Advertisement
Sign in to follow this  
musafir2007

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

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

If you intended to correct an error in the post then please contact us.

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.

Share this post


Link to post
Share on other sites
Advertisement
You can also use Control-F5 to Run instead of F5 to Debug. It will leave the Console Window open after the program completes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!