1.

Solve : Waiting to terminate??

Answer»

How can I make a batch file wait for a GUI application to close. Start /wait doesn't work with GUI applications (note the bolded text).

Quote

Starts a separate window to run a specified program or command.

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    WAIT        Start application and wait for it to terminate
    command/program
                If it is an internal cmd command or a batch file then
                the command processor is run with the /K switch to cmd.exe.
                This means that the window will remain after the command
                has been run.

                If it is not an internal cmd command or batch file then
                it is a program and will run as either a windowed application
                or a console application.

    parameters  These are the parameters passed to the command/program


If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just
    by typing the name of the file as a command.  (e.g.  WORD.DOC would
    launch the application associated with the .DOC file extension).
    See the ASSOC and FTYPE commands for how to create these
    associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE
    does not wait for the application to terminate before RETURNING to
    the command prompt.  This new behavior does NOT occur if executing
    within a command script.


When executing a command line WHOSE first token is the string "CMD "
    without an extension or path qualifier, then "CMD" is replaced with
    the value of the COMSPEC variable.  This prevents picking up CMD.EXE
    from the current directory.

When executing a command line whose first token does NOT contain an
    extension, then CMD.EXE uses the value of the PATHEXT
    environment variable to determine which extensions to look for
    and in what order.  The default value for the PATHEXT variable
    is:

        .COM;.EXE;.BAT;.CMD

    Notice the syntax is the same as the PATH variable, with
    semicolons separating the different elements.

When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name.  If it does, the
START command launches the Explorer on that path.  If done from the
command line, it is the equivalent to doing a CD /D to that path.
Although it says that it won't occur in the command script (bat file), it won't wait.In my testing 'start /wait notepad.exe' waits until notepad exits to continue.  try it Quote from: uSlackr on May 27, 2009, 10:42:19 AM
In my testing 'start /wait notepad.exe' waits until notepad exits to continue.  try it
Start /wait firefox.exe does not wait.
start /wait firefox.exe works for me as expected under Vista Quote from: uSlackr on May 27, 2009, 03:42:00 PM
start /wait firefox.exe works for me as expected under Vista
Try this and see...It only waits for it to load.

echo off
echo 1
start /wair firefox.exe
echo 2
pauseHelpmeh is right, start /wait doesn't wait for termination of any GUI program.
I forget the specifics but you'll need to write a program specifically for this.

using some goofy convolution of createProcess(). just start the process, and then call WaitForSingleObject() on the ProcessID.you could also make a loop to test to see if the process is still active. if the process is active wait and check again. Code: [Select]echo off

set appName=firefox.exe

start /wait %appName%
echo.App is running...
tasklist |findstr %appName% >nul && call WAIT
echo.App in not running...
pause

:WAIT
tasklist |findstr %appName% >nul || exit /b
ping -n 1 -w 1000 1.1.1.1 >nul
goto WAIT
sth like this ?That would only work on computers with tasklist, of course you could put tasklist into the same ZIP as the batch script.. Quote from: macdad- on May 28, 2009, 12:24:22 PM
That would only work on computers with tasklist, of course you could put tasklist into the same ZIP as the batch script..
Which is XP PRO and possibly Vista...I have Home edition...but I could get tasklist...This worked for me. I am on a PC running XP Pro.

Code: [Select]echo off

start /wait firefox.exe

echo on
Quote from: TheHoFL on May 29, 2009, 11:12:07 AM
This worked for me. I am on a PC running XP Pro.

Code: [Select]echo off

start /wait firefox.exe

echo on
echo off
echo 1
start /wait firefox.exe
echo 2
pause

Try that. It is supposed to wait until firefox closes...it only waits until it finishes loading."When executing an application that is a 32-bit GUI application, CMD.EXE
    does not wait for the application to terminate before returning to
    the command prompt."

The above specifies one exception -
" This new behavior does NOT occur if executing within a command script."

Perhaps there are other exceptions yet to be declared.

Firefox breaks the rules.  Is it a proper 32 bit GUI ?

I have just launched two instances of Firefox, and two of Notepad.
Windows Task Manager reports two instance of each on the "Applications" tab
and two Notepads but ONLY ONE Firefox on the "Processes" tab.

Incidentally, when all Firefox instance are closed, they disappear from the Applications Tab, and normally the Firefox process also shuts down, but sometimes it gets stuck and then CCleaner is unable to clear the Firefox cache until Task Manager has been launched and the Firefox process selected and terminated.

I think Firefox is not a suitable choice for evaluating what happens with "normal" software.


I am puzzled - what is meant by
" This new behavior does NOT occur if executing within a command script."

What was the OLD BEHAVIOUR that differs from the "new behavior" ?
Was it to wait for termination regardless ?
Was it to NOT wait for termination regardless ?
Was it that waiting was not subject to a 32 bit GUI restriction ?

What is "32-bit GUI application" ?
Does this apply to both windowed application and console application.

Does the above only apply when the /WAIT option is used ?
Or does it apply regardless (since this whole condition is not indented under the /WAIT description) ?

Regards
Alan
Quote from: ALAN_BR on May 30, 2009, 04:01:43 PM
but ONLY ONE Firefox on the "Processes" tab.
I get 1 per open window...

If you right click on each open task, and select go to process, it should give you more than one process.

Quote from: ALAN_BR on May 30, 2009, 04:01:43 PM
I think Firefox is not a suitable choice for evaluating what happens with "normal" software.
I'm not trying to evaluate "normal" software, I'm trying to wait for firefox to terminate. The quote I got from the command prompt (and my testing too), implies that start /wait will not wait for firefox to terminate, which is what I am trying to ACCOMPLISH.


Discussion

No Comment Found