gpt4 book ai didi

windows - 连续执行2个批处理脚本

转载 作者:可可西里 更新时间:2023-11-01 11:26:41 32 4
gpt4 key购买 nike

我有 2 个批处理脚本:

sleep 1.bat

echo sleep 4 seconds
timeout /t 4
exit

sleep 2.bat

echo sleep 3 seconds
timeout /t 3
exit

是否可以连续执行sleep1.batsleep2.bat,让程序总共休眠7秒?

sleep 主程序

call sleep1.bat
call sleep2.bat
pause

SleepMain.bat 无法执行我想要的操作。它只执行slee1.bat,因为sleep1.bat包含exit

sleep1.batsleep2.bat 是别人写的,我希望我不必更改它们。

最佳答案

是的,exit肯定会退出,但它退出的是控制台,而不是当前的批处理脚本。
要防止这种情况发生,请使用exit/b

提示:

  1. Use exit only in the main script.
  2. If you're just doing some simple thing in sleep1.bat, you can choose to not to add an exit /b command.
    Try it yourself : 1.bat - set "you=you", 2.bat - set "you=you" & exit /b
    In 3.bat, try either call 1.bat & echo %you% or call 2.bat & echo %you%, you will still get you as the output. This mean either script with exit /b or none still can access the variables in the previous called batch script. (Safe to try with simple script)

关于windows - 连续执行2个批处理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560695/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com