0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This solved it for me. I thought I had checked, but it turns out the other bat file was changing directories.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.