0

I have a weird problem where I have a simple batch file that runs another batch file, outputs what is on the screen to a log file, and then attempts to open the log file. The problem is, the log file doesn't open. Here is the code.

echo %date%, %time%: Deploying web site to Test1. > deploy.bat.log
Archive.deploy.cmd /Y /M:Test1 /U:<User> /P:<Password> >> deploy.bat.log
start "" notepad.exe deploy.bat.log

Through trial and err, I discovered that commenting the call to the external batch file makes the log file open, as expected.

echo %date%, %time%: Deploying web site to Test1. > deploy.bat.log
REM Archive.deploy.cmd /Y /M:Test1 /U:<User> /P:<Password> >> deploy.bat.log
start "" notepad.exe deploy.bat.log

Just to check, I also swapped out the other batch file with one that simply does echo Hello World, but the problem remains - the log file does not open. I thought that there was something going on in the other batch file that was causing it to fail, but it does not appear to be the case - this example is still not working.

echo %date%, %time%: Deploying web site to Test1. > deploy.bat.log
Hello.bat
start "" notepad.exe deploy.bat.log

My question is, why doesn't the log file open and how do I fix it so it does?

1 Answer 1

1

cmd chains to a batch file, ie the called batch file replaces the calling batch file and does not return, so any calls after the batch call will never be seen. If you want to return from a batch file you must use the call command, as in:

echo %date%, %time%: Deploying web site to Test1. > deploy.bat.log
call Hello.bat
start "" notepad.exe deploy.bat.log

Not what you might expect, but an early bad design decision in DOS is still with us, I'm afraid. I am not sure how many DOS1 batch files are used in modern Windows versions, but I can hazard a guess.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .