views:

258

answers:

3

Hi,

I have the following problem:

I have created a batch script which calls itself in there (for being able to write a log in parallel). In the script I start another process (like start startServer.bat) which starts up a java process and keeps opened up all the time.

In my original script I wait 30 seconds, check if the process is running and do an:

exit /B 0

Unfortunately that does not work, the window shows that the exit /B 0 is being evaluated, but the window still keeps open. When I close the window with the other process (meaning the "child" processes started up in my .bat) my script continues its run.

So:

scriptA.bat

-> in there I call: start startServer.bat
-> wait 30 seconds
-> check is server is started
-> exit /B 0
Process hangs up!

What's very odd, if I wrap another script around, like:

scriptB.bat

-> call scriptA.bat
-----> in there I call: start startServer.bat
-----> wait 30 seconds
-----> check if server is started
-----> exit /B 0
-> scriptA.bat continues without any hangup!

I also tried the same with exit 0 (without /B) also, same result! In the first case it hangs up, in the second case my window closes as expected...

Has anyone of you ever had such a problem before and knows what's wrong here? Process hangs up!

A: 

There's a good explanation of all the options for exiting a batch script here: http://www.robvanderwoude.com/exit.php

Specifically, from that page: The DOS online help (HELP EXIT) doesn't make it clear that the /B parameter exits the current instance of script which is not necessarily the same as exiting the current script. I.e. if the script is in a CALLed piece of code, the EXIT /B exits the CALL, not the script.

So you definitely don't want exit /b 0 in this case. If just exit 0 doesn't work, try GOTO:EOF.

Vicky
But for goto:EOF I am not able to hand out an errorlevel, right? :S
murxx
I tried with goto :EOF but no difference:D:>goto :EOFThen the process hangs until I close the other process windows! ;(
murxx
A: 

I found an answer - I do not know why this is not working but:

When I call the script with "call scriptA.bat | tee log.txt" the script hangs up and waits for the windows to close down. When I call the script with "call scriptA.bat > log.txt" the script does not wait and it works.

Has anyone an idea why this is happening???

murxx
A: 

I guess your problem lies within the start command. The following excerpt from the start /? help might point to the issue:

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.

As a solution you could try to modify the start command like this:

start "" cmd /c "startServer.bat"
Frank Bollack
No, that does not work as well...As I said it works as follows:call scriptA.bat > log.txt-----> in there I call: start startServer.batBefore that I used:call scriptA.bat | tee log.txt-----> in there I call: start startServer.batWith the tee-command it does not work out, whyeverso...
murxx
@murxx: Thanks for the feedback. In general you should post as many details about your issue as possible. Otherwise its quite hard to "guess" where the problem might be to find. Best is, you alway show the code that makes Problems.Also, you should start the habbit of accepting useful answers to your questions.
Frank Bollack