Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slowing a batch file down to read errors

Tags:

batch-file

With batch, if you get an error, the most you see of it is a flash of text and then the program ends. Is there anyway to have it slow down? or to have it stop before closing when it hits an error?

Thanks

like image 615
Gareth Jones Avatar asked Oct 22 '11 21:10

Gareth Jones


Video Answer


2 Answers

If you execute your Batch file from the command-line in a MS-DOS window and an error happens, you can just review the text in the window to see what happened.

On the other hand, if you execute the Batch file via a double click in the explorer you see nothing if the Batch file have an error. Is this your case? If so, the easiest solution is to test the Batch file in a MS-DOS window until it works ok.

However, if you still need a method to stop closing the DOS window when the Batch file ends, you can do that this way:

  • Right click on your Batch file and select Create shorcut, a Shorcut is created.
  • Right click on the Shortcut and select Properties
  • In Target, after the "C:\Path\filename.bat" string add: & PAUSE
  • Select OK

This way, when you execute the Shortcut via a double click, the DOS window will execute a PAUSE after the Batch file ends for any reason.

like image 118
Aacini Avatar answered Oct 12 '22 23:10

Aacini


Redirect the output with > to capture it in a file.

You might need: command > file 2>&1

like image 33
bmargulies Avatar answered Oct 13 '22 01:10

bmargulies