How to call one batch file after another

后端 未结 6 1962
闹比i
闹比i 2020-12-14 16:23

I have a batch file that i am testing, all i want to do is the following

CALL ping.bat

Then after that batch file has run i want to run ano

相关标签:
6条回答
  • 2020-12-14 16:23

    don't call the file you are calling from the batch the same name as the command you are trying to invoke...renamed to gnip.bat and works fine

    0 讨论(0)
  • 2020-12-14 16:28

    Check that you don't have exit somewhere in the first batch. Some people habitually use that to jump out of a batch file which is not the proper way to exit a batch (exit /b or goto :eof is).

    Another option is that you might call another batch in the first one without call.

    0 讨论(0)
  • 2020-12-14 16:32

    The ping command acts differently on different operating systems. Try forcing the ping command to stop after a few echo requests with a -n switch.

    ping -n 4 127.0.0.1

    0 讨论(0)
  • 2020-12-14 16:34

    Assume you have 3 batch files.

    1. ping1.bat which has the content ping 127.0.0.1
    2. ping2.bat which has the content ping 127.0.0.1
    3. ping3.bat which has the below two lines
      call ping1.bat
      call ping2.bat

    If you have all the three batch files in a single folder,(lets say under C:\NewFolder) then if you double click ping3.bat, you won't get any error for sure.

    Note: If you don't want to wait for the first command to complete, then use start keyword which just initiate the process and proceed with the next line in the batch file, whereas call will do it sequentially(comes to next line only after the current process completes , start allows parallelism)
    To do it parallel use the below two lines of code in the ping3.bat:

    start ping1.bat
    start ping2.bat

    0 讨论(0)
  • 2020-12-14 16:43

    Not exactly sure what you wanted to do here, but I assume that you wanted to do this:

    1. run FIRST.bat
    2. from FIRST.bat you wish to call SECOND.bat
    3. While SECOND.bat is executing, FIRST.bat should remain paused
    4. After SECOND.bat finishes its execution, FIRST.bat should resume and call THIRD.bat

    In that case, from your actual batch file, you should start ping.bat and ping2.bat like this:

    ::some code here
    start /wait ping.bat
    start /wait ping2.bat
    ::some code here
    

    Then in both ping.bat and ping2.bat the last line should be exit. Their code should look like this:

    ::some code here, might be ping 127.0.0.1
    exit
    

    So now your actual batch file will start ping.bat and it will wait for it to finish (exit). Once the ping.bat closes, your actual batch file will go to the next line and it will start ping2.bat etc.

    0 讨论(0)
  • 2020-12-14 16:49

    There's a chance your ping.bat is simply calling itself, if its contents is merely ping 127.0.0.1, as you say.

    I would append .exe after ping to make things sure.

    As jeb has by all means justly suggested, choosing a different name for your batch file is an even better solution.

    0 讨论(0)
提交回复
热议问题