0

I have the following two batch files, bat1.bat calls bat2.bat.

bat1.bat:

@echo off
echo bat1 start >> C:\battest\log.log
call bat2.bat
echo bat1 end >> C:\battest\log.log

bat2.bat:

@echo off
echo bat2 >> C:\battest\log.log

When I run bat1.bat directly in command line, the output is as expected as below:

bat1 start 
bat2 
bat1 end 

However, when I create a task in Windows Task Scheduler to run bat1.bat, I only get this:

bat1 start 
bat1 end 

It seems the call bat2.bat has no effect. Why?

metropolision
  • 385
  • 3
  • 10
smwikipedia
  • 52,824
  • 76
  • 267
  • 432

1 Answers1

2

OK, I figured it out.

When I run it directly in command line, the working directory is C:\battest.

However, when it is executed by Windows Task Scheduler, the working directory is C:\windows\system32, but there isn't the file bat2.bat.

I need to specify the full path of bat2.bat as below:

call C:\battest\bat2.bat
jeb
  • 70,992
  • 15
  • 159
  • 202
smwikipedia
  • 52,824
  • 76
  • 267
  • 432