britter
britter

Reputation: 151

CMD ECHO doesn't print to file after redirecting

I'm trying to run a bat file from within another bat file and redirect the output. That's working fine. However, after that call to the bat file has finished, I want to print to one of the files I've been redirecting to, but it doesn't appear to be working.

Here's what I'm doing right now.

@ECHO OFF
call %1 2> error.log 1> compile.log
echo Complete >> error.log

My hope is that the Complete text is appended to the log when bat file finished running. However, it never writes out. The log only contains output from the bat file I'm calling.

Any suggestions? Thanks.

Upvotes: 0

Views: 406

Answers (1)

Mofi
Mofi

Reputation: 49216

I can think of 2 different reasons for this behavior:

  1. The batch file called with call %1 changes the current working directory. This results in Complete written to a different error.log as before because working directory has changed in the meantime. The new current working directory could be also write-protected resulting in no error.log created at all.

  2. The batch file called with call %1 contains command exit without parameter /B which results in an immediate exit of running command line process. In this case the line with echo below call is never executed. See short help output in a command prompt window after entering either help exit or exit /? about exit /B.

Upvotes: 2

Related Questions