batch-file - 在第一个持久程序使用批处理命令完成初始化后,如何执行第二个程序?
问题描述
我正在使用批处理文件来运行两个不同的可执行程序。我希望第二个程序在第一个程序完成初始化并在我的计算机上打开一个端口后运行。
我知道顺序命令排序的call和/wait命令,尽管第一个程序是一个持久应用程序,它在我的计算机上打开一个端口;因此,它永远不会“完成”运行。关闭可执行文件的命令提示符会关闭端口。由于这种行为,如果我使用上述任一命令,则第二个调用的程序在第一个之前完成运行并导致问题。我意识到这种解释有些令人困惑,但如果需要澄清,我会提供更多背景信息。谢谢。
编辑:使用@shadoe2020 的代码并删除条件语句。
:: This file starts the mongod.exe and mongo.exe executables.
:: @ECHO OFF
start C:\Users\jacob\mongodb\bin\mongod.exe
:search
tasklist|find "mongod.exe"
TIMEOUT /T 3
GOTO found
:found
start C:\Users\jacob\mongodb\bin\mongo.exe
GOTO end
:end
PAUSE
解决方案
:: This file starts the mongod.exe and mongo.exe executables.
:: @ECHO OFF
start C:\Users\jacob\mongodb\bin\mongod.exe
:search
ver > nul
tasklist|find "mongod.exe"
IF %ERRORLEVEL% EQU 0 GOTO :found
TIMEOUT /T 5
GOTO search
:found
start C:\Users\jacob\mongodb\bin\mongo.exe
GOTO end
:end
PAUSE
在发现进程说 20 秒以允许程序 1 连接到您正在连接的任何东西之后,您甚至可以检查进程怎么样。
推荐阅读
- pytorch - 如何从磁盘加载torchvision 模型?
- linux - nasm write 系统调用不适用于 64 位版本如何解决?
- reactjs - Reactjs 从本地网络外部的后端获取数据
- java - 如何让我的 AlarmManager 在所有手机上工作 && 如何获得安排我的闹钟的权限而不删除它们
- excel - 添加工作表后Excel“此操作不适用于多项选择”
- python - Arcpy 脚本不断给出错误“TypeError:预期的字符串或类似字节的对象”
- grpc - 使用 java-grpc-prometheus 获取 gRPC 服务指标
- typescript - 如何在打字稿中获取泛型类型参数?
- spring-boot - 如何在spring boot项目中定义一个没有content-type的rest服务
- docker - 无法安装 Docker Compose v2:“无效插件,执行格式错误”