Detecting if a .bat file was run in the console that was allocated to it

Possible duplicate:
Conditional PAUSE (not on the command line)

I have a .bat file that does some processing and prints some result, and people will probably want to check this output. Different people (depending on their personal preferences and workflow) run this file in different ways: some use the Start-> Run dialog, some start it from Windows Explorer, some start cmd.exe , and then run this .bat file.

If I just put pause at the end of the .bat file, it will allow users who do not start it from cmd to view the output, but it upsets those that start it from cmd because they have to press any key for no reason (in in any case, they will not lose output). If I do not put this pause , then people who do not use cmd will not see the result.

I want to determine if a new console has been allocated to run the .bat file and whether or not to start pause depending on it. Is it possible? Or are there any other solutions?

+4
source share
2 answers

add an argument to the package, which, when launched from the shortcut, will activate the pause, but when launched from cmd.exe will not

iow:

 if "%1"=="" goto nopause pause :nopause 
+3
source

The easiest way is to create two .bat files that differ only at this point.

Alternatively, you can use the main .bat and .bat, which calls the main batch file with a parameter that says "please close me when you have completed your task."

+1
source

All Articles