1

On Windows 10.

I've tried looking at other questions but all the solutions were for either .exe files that you run yourself from the command line, or .bat files.

I'm using a program with a GUI that runs other exe files itself, and I'm trying to record the cmd window output when those exe files are opened.

I can't just call the exe's directly because the main program with the GUI is handling all the arguments etc required by those other programs it's executing.

Is there any way to prevent the cmd window from closing when these exe's are run?

edit: not a perfect solution but ctrl+C pauses the execution and brings up a prompt inside the cmd window "Terminate batch job (Y/N)?" which gives me a chance to manually copy all the output before it. Not ideal but thought I'd share just in case someone else would find it useful.

4
  • 1
    Unless these command bash scripts, have code in them that results in a user prompt of some kind at the end of the prompt, they are going to close at the end of their execution per their design. If these are command prompt executables, writing in something like C#, or C++ there is no way to prevent their closure at the need of their executation.
    – Ramhound
    Mar 18, 2022 at 18:59
  • Can you add a pause into the GUI's call, either by modifying the GUI file itself (see resource-editor.com/how-to-edit-strings.html ) or by "injection" into the parameters? Mar 18, 2022 at 19:02
  • @Ramhound, unless this is executed under the Linux subsystem, bash shell would not be invoked. Also, even truly compiled languages, such as C++ or Delphi, may use string tables, which might be editable -- or not. Mar 18, 2022 at 19:05
  • The author made no mention of this being a Linux application running within WSL2. I have my doubts this has anything to do with WSL2.
    – Ramhound
    Mar 18, 2022 at 19:30

2 Answers 2

1

If you can create or alter a shortcut that launches the exe file, you can set it to the following:

cmd /k c:\path\program.exe

What this does is create a cmd window, launch your program in it, and then keep the window open afterwards. You can type in it as it is a normal program, until you either click the x or type in exit.

Then you double click the shortcut and it works.

It is not possible to configure cmd to always remain open when launching an exe file that runs through console.

Alternatively, you can first start a cmd prompt by clicking in the addressbar where the .exe file is residing so you can type there and simply type in cmd to launch cmd in that window, and then type the name of your program.

If this is still not what you're looking for, please edit your question and elaborate what the program with GUI is that you are running, and what configuration options you have.

1
  • Hmmmm,....what about "Start"? - (start "Say that Again" /wait cmd /c "%systemdrive%\Path\To\App.exe")
    – Danijel
    Jan 22 at 5:26
-1

When I used to create Console Applications using C#, I used to face this issue when the CMD window used to close after doing its job. This is as per design, but there is one way to stop that from happening and that is by asking for a user input at the end of your process so that the CMD window waits for you to press any key before it finishes exits from the process and closes.

In C#, the last statement of the program has to be System.ReadLine() but it could be anything similar based on your programming language.

Hope that helps.

2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 18, 2022 at 19:53
  • -1 there is nowhere mentioned that they use a programming language. I'm more sure they have a program that they have a button in that they press that runs a script and they want to catch the output of that script.
    – LPChip
    Jan 22 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .