Running command-line in batch file

2019-08-07 03:29发布

问题:

I have the following code which doesn't seem to be working properly - is someone able to assist with how to run command-lines in batch files

@echo off

set changeFrom=321
set changeTo=123
set origFile=config.txt
set newFile=config1.txt

test.bat %changeFrom% %changeTo% %origFile%>%newFile%
del %origFile%
ren %newFile% %origFile%

::end

I have a file "test.bat" which has code to replace strings in a file - but I Don't get how it can work ?

回答1:

You need to use call to execute the second bat file from the first like this:

call test.bat %changeFrom% %changeTo% %origFile%>%newFile%

without call the first batch script will exit when the second one exits.