Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Obviously, /wait is given for start command. But this is totally weird –  Starx Jul 27 '11 at 2:36
    
Did you try it without the @echo off to see what is going on? –  jftuga Jul 27 '11 at 2:59
    
@jftuga, Just tried it, it is executing as it should? Just not functioning as it should :( –  Starx Jul 27 '11 at 3:06
    
Also, looking at the full source, IIRC, the ERRORLEVELS for CHOICE should start highest to lowest... Am I right? –  Canadian Luke Jul 27 '11 at 16:27
    
@Luke, Yeah, I tried highest to lowest first, but it didn't work, so had to go the other way. –  Starx Jul 28 '11 at 4:36

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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 Jul 27 '11 at 8:33
    
@Starx, I just clarified my answer a little to explain the start command a bit better. –  Mokubai Jul 27 '11 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.