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

标签 windows batch-file

我有 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/

相关文章:

excel - 有没有办法从 CSV 中获取行而不加载整个文件?

windows - Vista 控制台应用程序?

ruby - 如何从 bash 脚本同时启动多个 Ruby 脚本

python - Neo4j 性能调优

html - 按批处理文件打开页面时,HTML音频不会播放

windows - twisted 中的 iocpreactor 发布状态

c++ - 如何使用 Code::Blocks 或 MinGW 在 Windows 上构建 CPP-NETLIB 库

windows - 为什么不鼓励在 Windows 上将 PPM perl 模块与 Strawberry perl 一起使用?

windows - 如何在 Windows 中使用带路径的 "start"和带空格的命令创建批处理文件

batch-file - 连接两个字符串 'present working directory' 和 'app.exe' 文件名以构建绝对路径