tik27
tik27

Reputation: 2698

batch started process locking log file

I have a batch file which calls another batch file that starts a Java server. The problem is that the java process is somehow locking the file I'm redirecting to on the main batch file.

@echo off

code......

echo shut down server
call %serverBin%\server stop worklightServer
rem net stop WLPServer

more code.....

echo start server
call %serverBin%\server start worklightServer
rem net start WLPServer

Im starting this batch file with
E:\IBM\wlp\bin\worklightRestart.bat >> E:\IBM\wlp\bin\restartWorklight.log

The problem is that this script can only run once, then fails every other time.
It seems that the java process that is start by the server.bat is locking the restartWorklight.log file.

Not sure why.

Upvotes: 0

Views: 938

Answers (1)

MC ND
MC ND

Reputation: 70943

When you start the batch file, the stdout stream is redirected. The programs started from inside this process "inherits" this situation so while they are still running, they hold the lock on the file.

The problem is that as the way you are starting batch file needs a lock on the log file, you can not start the process to stop the server. If you place the redirection to the log file in the line where the background process is started, stopping the server will release the lock.

Upvotes: 1

Related Questions