Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a batch file so that results remain visible on completion

I run batch files and they exit immediately. I dont want that to happen so that i can see my output. Can someone tell me how to make this happen ?

I use windows 7.

like image 945
gregnorm Avatar asked Jun 12 '13 19:06

gregnorm


People also ask

How do I run a batch file without displaying execution?

Solution-1:Create a VBScript file lets say Master. vbs and call your My. bat file within it. It'll run your batch file in invisible/hidden mode.

What is %% A in batch script?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

How do you make a batch file not close?

Add a pause statement to a batch file If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.

How do I keep the console open after executing a batch file?

If you want the command prompt cmd widnow to stay open after executing the last command in batch file –you should write cmd /k command at the end of your batch file. This command will prevent the command prompt window from closing and you'll get the prompt back for giving more commands in the cmd window.


3 Answers

Adding pause is a good answer. Here are some other ways as well..

Rather than double-clicking on them to execute you can run from a command line:

  1. Press the windows key + r (this opens the "run" window)
  2. Type: cmd into the text input and press enter (or click ok)
  3. Change to the directory that contains the batch file, e.g: cd c:\scripts\foo
  4. Execute the batch file by typing it's name and pressing enter, e.g: somename.bat

If there is a lot of output and it scrolls off the screen you can direct the output to a text file instead like so:

somename.bat > output_filename.txt

Then you can open the 'output_filename.txt' file in any text editor to view/search all of the output. This is better than pause when there more output than what is available in the scrollback.

like image 187
Drew Avatar answered Nov 15 '22 14:11

Drew


Put this on the very last line of the Batch:

cmd /k
like image 30
captcha Avatar answered Nov 15 '22 14:11

captcha


Add the pause command at the end of your batch file. This waits for you to key something in.

(The nice thing is that if you're running the batch file from a non-interactive process, such as a automated build system or scheduled task, the pause is simply skipped.)

The help message for pause is:

C:\>help pause
Suspends processing of a batch program and displays the message
    Press any key to continue . . .

If there is lots of output and you can't scroll far enough back, adjust the screen buffer height of the command window. This can be done via right-click on the c:\ icon go to properties -> layout:

enter image description here

like image 38
Macke Avatar answered Nov 15 '22 14:11

Macke