开发者

Semantics of Windows batch programming redirection

I have a Windows batch script (my.bat) which has the following line:

DTBookMonitor.exe 2>&1 > log\cmdProcessLog.txt

So, from my understanding, this runs DTBookMonitor, redirects STDERR to STDOUT and then redirects STDOUT to the file log\cmdProcessLo开发者_StackOverflowg.txt.

I then run my.bat. DTBookMonitor runs for a significant amount of time, and when I run my.bat a second time (while it is already running), it immediately exits from the second instance of my.bat.

Is this purely because of the redirection to cmdProcessLog?


Better late then never :)

Windows redirection locks the output file so that no other process can open the file for writing at the same time. That is why the second instance fails when it tries to redirect output to the same file.


I'd guess it's either due to that, or because DTBookMonitor only allows one instance of it to run at a time. The following test should shed some light on the situation:

  • Run the first (long) instance of DTBookMonitor
  • Run a second instance without redirecting any of its output
  • Alternatively, run a second instance, but redirect the output to a file other than log\cmdProcessLog.txt

Do you get similar results? Different results?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜