Windows – Batch program not functioning as it should!

command linewindows

I created a batch script (view in full here) to start some services first and then an application. After the application is complete, the batch is suppose to GOTO somewhere but it is waiting for the program to exit, to continue further.

Header to start the application and proceed:

:vmSTARTAPP
    "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"
    IF NOT %BACK%==NULL GOTO %BACK%
    GOTO STARTAPPCONT

This header is called from another header:

:STARTAPP
    cls
    echo Starting Application
    GOTO %BATCH%

%BATCH% contains the name for the next header – in the above case, vmSTARTAPP.

If I run it from a new Command Prompt window it works fine, just not in this batch.

What am I doing wrong?

P.S. Do not refer this question to my previous question. This is a completely different case.

Best Answer

Could you try replacing your lines that show

:vmSTARTAPP
    "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"

with

:vmSTARTAPP
    start "Starting VMWare" /B "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"

I'm assuming you want to silently start VMWare and carry on without stopping and this should, in theory, do that.

The start command instructs DOS to run the command you are passing to it (in this case "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe") and by default does not wait for for the command you pass it to return and instead runs it in a separate process.

By default every line you have in a batch file is run sequentially and waits for every line to execute and return before moving on to the next line. The start command gets around this by launching the program you pass it in a separate process (DOS window) and so your batch file encounters this line, runs it as it normally would, sees that the start command has returned (after creating a new process to run your command in) and your batch file carries on as if nothing unexpected has happened.

The "Starting VMWare" title is simply that, a title, the newly created DOS window would have that title if it were not for the /B argument which tells it not to show the new DOS window. The title is kind of necessary but kind of optional and I've had an occasional WTF moment in scripts without it, but those times are more the exception than the rule.

You can find a bit more info on the Start command at http://ss64.com/nt/start.html

Related Question