0

As project need, I need to create some batch job like a.bat, b.bat.

and I use Task Scheduler to call these batch job.

but find call failed.

I check the reason that the batch job file will call other file.and cannot find the path.

for example a.bat

@echo off

call Variable.bat

set a=1

set b=2

.........

The error said Variable.bat cannot find.

I know use

@echo off

cd filepath

call Variable.bat

set a=1

set b=2

.........

can solve that problem.

but different server the file path are different, every time change server,then need to change path again. if have many batch jobs ,then change path need to much time.

Do have some other way to solve this ?

When change different server, I don't need change any batch job code

Note:

just double click .bat file can working.

the Task Scheduler seems need start file folder

Jack.li
  • 55
  • 2
  • 10
  • I would probably do something like this: http://stackoverflow.com/questions/2763875/batch-file-include-external-file-for-variables store the variables (the servername) in a config file by themselves and call that from all the batch files. That way when the servername changes you only need to amend it once in your config file – n34_panda Sep 18 '14 at 07:43
  • Actully I do like this, the Variable.dat store the variables(the servername and others), but first time ,call this one ,the task scheduler cannot find the Variable.dat file path. – Jack.li Sep 18 '14 at 07:49
  • Are both files in the same folder? – MC ND Sep 18 '14 at 08:05
  • Yes, if not the same folder ,then double click cannot working – Jack.li Sep 18 '14 at 08:09
  • if files in the same folder you could try amending the "start in" setting to use the same directory as well... – n34_panda Sep 18 '14 at 15:39
  • Thanks a lot, this one can work. – Jack.li Sep 19 '14 at 03:28

1 Answers1

1
@echo off

    call "%~dp0Variable.bat"

    set a=1
    set b=2

%~dp0 is the drive and path (with an ending backslash) where the current batch file is stored

MC ND
  • 69,615
  • 8
  • 84
  • 126