4

Possible Duplicate:
Conditional PAUSE (not in command line)

I have a .bat file that does some processing and prints some output and people likely want to check that output. Different people (depending on their personal preferences and work flow) run this file differently: some using "Start->run" dialog, some start it from explorer, some start cmd.exe then start this .bat file from there.

If I just put the pause at the end of the .bat file it will allow users that don't run it from cmd to see the output, but it frustrates the ones that run it from cmd because they are required to press any key for no reason (they will not loose output in any case). If I don't put that pause then people that don't use cmd will not see the output.

I want to detect if the new console was allocated to run the .bat file and run or not run pause depending on it. Is it possible? Or is there any other solutions?

Community
  • 1
  • 1
n0rd
  • 11,850
  • 5
  • 35
  • 56

2 Answers2

3

add an argument to the batch which when run from the shortcut will cause the pause to be activated but when run from cmd.exe will not

iow:

if "%1"=="" goto nopause
pause
:nopause
AndersK
  • 35,813
  • 6
  • 60
  • 86
  • The problem is that of all users no one uses shortcuts: they either run it from start->run or just double click the .bat file in explorer. – n0rd Nov 06 '10 at 12:10
  • But anyway it gives some food for thought – n0rd Nov 06 '10 at 12:11
1

The easiest way would propably be to create two .bat files that only differ at that point.

Alternatively, you can use a main .bat and a .bat which calls the main batchfile with a parameter that says "please close me when you've done your task".

thejh
  • 44,854
  • 16
  • 96
  • 107