.bat script only executes 1 line

2019-05-29 14:36发布

I'm writing a script that performs the same function several times, but when I run the script only one of commands executes leaving the rest not executed after the .bat file has run.

Does this have to do with the long time it takes for my commands to run (15-20 sec)? I've written plenty of bat files and I've never run into this. Do I need to have a sleep function between each command?

I've been trying to figure this one out on google, but my available search terms makes my search results vague and difficult.

Any help is definitely appreciated.

the bat file looks something like the following

IF input1 == "search term" goto location
do something
do something
do something
etc
goto end of file
:location
do something else
do something else
do something else
...

1条回答
你好瞎i
2楼-- · 2019-05-29 15:21

Does one of your "do something else" lines involve calling another batch file? If so, do you use the CALL command?

If you want to call another batch file recursively, you need to use CALL. Otherwise, when the called batch file exits, it does not return to the calling batch file and simply exits. This is a relic from the MS-DOS days; since memory was at a premium, the MS developers decided that the batch interpreter shouldn't keep a call stack by default -- so if you wanted one, you had to use CALL.

See call /? for more information.

查看更多
登录 后发表回答