7

An .exe which is runs via cmd.exe runs and then quickly disappears before I can read the error message. How can I get the cmd.exe window and error message to not close? Or is there anyway to log that error info that just flashed? Thanks.

7 Answers 7

5

Starting a program that launches console will indeed close the window, because CMD is no longer needed.

If you press start and type cmd and press enter, you will launch a command prompt.

Press the driveletter the program is on if this is not on C:, followed by a : and press enter.

In the below examples the _ at the end represents your cursor.

Example:

C:\Users\User>D:_

D:\>_

now, use the command cd to navigate to the directory of the program. You can press tab to autocomplete names. Tootab would make Tools if that folder exists.

Example:

D:\>cd Tools_

D:\Tools>cd "My Program"_   <- type 'My' and press tab to Autocomplete to "My Program"

D:\Tools\My Program>_

Now enter the name of the program you want to run.

Example:

D:\Tools\My Program>program_
Hello, I am the error message you want to see.

D:\Tools\My Program>_
10
  • 3
    you can use the /D switch to switch drive letters with cd so cd /D C:\Tools will always go to the directory no matter where you are currently Jul 4, 2014 at 11:01
  • I am aware, but I wanted to keep the post as simple as possible.
    – LPChip
    Jul 4, 2014 at 11:21
  • 1
    Easier way : open the explorer, navigate to the directory and call "cmd" from the address bar.
    – Lyrkan
    Jul 4, 2014 at 13:31
  • 3
    @LPChip It's a default feature of Windows 7/8 that works without any additional software. If you already opened the right path in the terminal there is an even more convenient way though: Shift + Right Click -> Open command window here
    – kapex
    Jul 4, 2014 at 13:50
  • 1
    Or even easier, open the command prompt, and drag and drop the program into it - Windows will insert the full path to the executable into the command prompt. Then just hit enter.
    – Moshe
    Jul 4, 2014 at 13:52
5

Normally when I have to do this I create a bat file in the same folder (so new text file rename to whatever.bat) open in text folder then type:

ProgramName.exe
Pause

Close and save then run the bat file and it should keep it open!

1
  • 3
    Can you add some instructions on how to do this? An average user that knows how to make a .bat file would also know how to pause at the end.
    – LPChip
    Jul 4, 2014 at 9:21
4

You can use .bat file to run that exe.

Also, you can use the following command in cmd to log the error/output of that exe file into a text file:

myFile.exe >> "C:\logFile.txt"

Double greater than symbol appends to the existing file " >> " however, single symbol overwrite the existing file ">".

Hope this will help you to log the error.

1
  • 4
    Actually, many programs print to stderr. >> will only log stdout. You need to add a 2>&1, e.g. command 2>&1 >>log.txt
    – Bob
    Jul 4, 2014 at 14:19
0

You need to run it in an already-existing instance of cmd.exe. You can press and hold shift and right-click in a directory then click "Open command window here". Then either type the name of an exe or click and drag it into the command window, then press enter.

0

According to this:

|| [...] command1 || command2 Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).

and if you are making that .exe, you just need to put pause command after your sentences.

And example in c++ that call the bash:

#include <iostream>
#include <windows.h>


using namespace std;

int main()
{
    system("cd  akfhaskfn|| pause");
    system("cd  || pause");

    return 0;
}

You will see that only the first one will call the pause command.

1
  • Welcome to Super User! While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
    – DavidPostill
    Aug 4, 2015 at 7:21
0

just a simple version of LPChip answer (works on windows 7) Press start and type cmd and press enter, you will launch a command prompt. Just drag and drop what you need to run (your python script or .exe) into the cmd windows, and press enter. (If you need to run the cmd as admin, find the cmd in the start menu, right click on it, choose run as admin)

0

Try to insert tihs

taskkill -im cmd.exe

You must log in to answer this question.

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