Monday, November 12, 2007

wait in windows bat script - good way

i recently wrote about using ping to pause for a number of seconds in a batch script. It was brought to my attention that you can use /wait to actually wait for a process to complete like so:

start /wait /i "unimportant title put whatever here" "C:\path\to\some\executable.exe"

or if you have an msi installer you can do this:

msiexec /i "C:\path\to\msiinstaller.msi" /qr


  1. Thx for your tips. You save my day!

  2. Hi!
    I am calling this .bat file through a .jsp using your advice..
    but it doesn't work....:-///
    there is this bat that calls for another that runs 2 .exe files
    It should doesn't..
    Don't know why...If you have any ideas I would be greatfull
    Note that of course!I have tested bats and cmd and so on...

  3. Cardi:
    that sounds like a horrible, bad design. You should really be doing that in a servlet (or never!), but hey.. its your code...

    anyway, why dont you call the exe files directly using something like this:

    Process p = Runtime.getRuntime().exec(new String[] {"some.exe" "arg1" "arg2" "etc");
    int returnCode = p.waitFor();

  4. Hmmm... A JSP is a type of servlet. It doesn't *need* to output a web page. You can change the content type by setting headers. It may not be a bad design. Some app servers require a bit more configuration to run a servlet than a .jsp. In the end, it is a minor "tomato/tomahto" thing. JSPs get compiled as servlets in the end. Perhaps the developer wants an executable to be called via the web. Seriously, bad design using a JSP, but a servlet is OK? They are the same thing!

  5. I guess what i meant is that this kind of logic needs to stay the hell out of the JSP and be done in the controller, not in the view. Doing inline java on the JSP is a known bad practice. At the end, the JSP will be compiled into a servlet, but it doesnt make it ok to put this kind of logic there.

    The JSP should DISPLAY some information, and not have to worry about error checking etc.

  6. very nice tip - solved my issue

  7. you can use TIMEOUT -T 180 /NOBREAK also

  8. hello, I am new to batch files and would like an easier way to do this. is there a way to do this in a few simple lines of code?