Batch program not functioning as it should!

2

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.

Starx

Posted 2011-07-27T02:30:13.767

Reputation: 1 881

Obviously, /wait is given for start command. But this is totally weird – Starx – 2011-07-27T02:36:05.913

Did you try it without the @echo off to see what is going on? – jftuga – 2011-07-27T02:59:20.793

@jftuga, Just tried it, it is executing as it should? Just not functioning as it should :( – Starx – 2011-07-27T03:06:24.687

Also, looking at the full source, IIRC, the ERRORLEVELS for CHOICE should start highest to lowest... Am I right? – Canadian Luke – 2011-07-27T16:27:23.100

@Luke, Yeah, I tried highest to lowest first, but it didn't work, so had to go the other way. – Starx – 2011-07-28T04:36:50.557

Answers

1

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

Mokubai

Posted 2011-07-27T02:30:13.767

Reputation: 64 434

Wow, thank you so much. It worked. BTW, what does start "Starting VMWare" do. I thought it was some kind of title but I didn't see it anywhere – Starx – 2011-07-27T08:33:08.233

@Starx, I just clarified my answer a little to explain the start command a bit better. – Mokubai – 2011-07-27T16:25:35.830