I have a program written in C#, console application. A .exe file is created and when executing the command window opens, writes the output and closes as usual. My problem is that I may need to see the output in the cmd (not always). Is there any command (as I call my exe file through cmd in order not to close the command prompt that specific time only)??
Asked
Active
Viewed 1,402 times
0
-
To do this **programmatically**, you need to check whether or not you are running the program in a debugger (in the latter, sometimes the console window is displayed). You can simply add a prompt when your program finishes telling the user to "Press any key to exit." and then simply close your program after the user enters *anything*. – Breakthrough Jul 01 '14 at 15:18
2 Answers
0
Try this (calling as my_command.bat):
@echo off
my_command.exe
pause
Leo Chapiro
- 15,459
- 5
- 42
- 45
-
1Thanks. This stops my cmd to close. But then I have to create 2 .bat files: 1 with the code above if I want to run without closing the cmd, and 1 (plain) if I do not the console output to be shown. What is the purpose of '@echo off' by the way? It prevents **pause** to be printed to the cmd? I've been looking for a week for an answer like yours. Thank you. – user3238433 Jun 30 '14 at 09:24
-
If you want to make the batch file more comfortable you can ask whether stop or not like here: http://www.wikihow.com/Create-Options-or-Choices-in-a-Batch-File – Leo Chapiro Jun 30 '14 at 12:00
0
Try the answer on How to prevent the command prompt from closing after execution?
This should give you the ability to choose what you want to do with the command prompt, after command execution.
user339212
- 1
- 1