嗨,我正在尝试编写一个执行两个命令的 Windows 命令脚本。第一个永远不会完全完成。相反,它会输出类似“程序已启动”的行,并且命令提示符保持打开状态。它运行大约需要一个小时。运行后,我希望它启动第二个命令。我只找到了一个接一个地同时或在等待条件下执行命令的方法。我想执行第一个命令,等到“程序已启动”行输出到屏幕,然后我想运行第二个命令。有什么办法吗?
call command1.cmd
call command2.cmd
call command3.cmd
call command4.cmd
'''Wait for a line to be output to the console, takes about an hour, line is 'Program has started'
call command2.cmd (in a new console window)
我目前将其设置为调用命令 1,然后调用命令 2,但是命令 2 永远不会被调用,因为命令 1 永远不会关闭。
@echo off
title
setlocal enableDelayedExpansion
if "%~1" == ":test" goto :test
if "%~1" == ":sender" goto :sender1
if "%~1" == ":receiver" goto :receiver
"%~f0" :sender | "%~f0" :receiver
exit /b
set quit=0
:sender1
call command1 :: waits for first 3 programs
call command2
call command3
start /b command4 :: The program that doesn't end
:sender
if %quit% equ 1 exit
set "str="
set /p "str=>" >&2
echo(!str!
if !str! neq QUIT&&!quit! neq 1 goto :sender
cls
exit /b
:receiver
set "LINE="
set /p "LINE="
echo !LINE!
if "!LINE!" equ "Program has started" start /b "" %0 :test :: EDIT KEYWORD HERE
if !LINE! neq QUIT goto :receiver
set quit=1
:test
endlocal
start command5 :: triggered after command 4 prints "Program has started"
exit