批处理文件等待程序复杂的命令行完成
我需要这个完成后才能运行此命令在批处理批处理文件等待程序复杂的命令行完成
LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script
下一行应该进行处理。现在,有很多方面,BT我在 The system cannot find the file specified.
喜欢的东西一样容易START /WAIT
,但无论我怎么努力,运行这个与START
结果demon.devin的回答后,这是解决方案:
:CHECK_RUNNING
set errorlevel=
tasklist /fi "imagename eq noppack.exe" | find /i "noppack.exe"> NUL
if /i %errorlevel% GTR 0 goto CONTINUE
ping -n 1 -w 5000 1.1.1.1 > nul
goto CHECK_RUNNING
:CONTINUE
[...]
我没有测试过这一点,但也许这可以帮助..
@echo off
goto begin
:: INFO: Check to see if a process is running and if so wait before launching
:: a new process. After checking for a process this .bat file will wait
:: for a set amount of seconds declared be the user before checking and
:: looping again or moving onto the next command.
:: EDIT: Change "seconds=" to "seconds=15000" to set a time of 15 seconds for
:: the wait period. For 5 seconds change it to "seconds=5000" For extra
:: commands you should add "set app3=AnotherProcess.exe" and repeat for
:: more if need be but be sure to compensate for the new command below.
:begin
:: Set length in seconds here
set seconds=
:: Set your processes here
set app1=noppack.exe
set app2=NewProcess.exe
:: Do not edit
:: First loop check
echo.
echo.
echo Starting the LEProc.exe process...
LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script
:check_one
cls
set errorlevel=
tasklist /fi "imagename eq %app1%" | find /i "%app1%"> NUL
if /i %errorlevel% GTR 0 goto complete_one
echo.
echo The %app1% process is running!
echo.
echo Will check again in a few seconds.
echo.
ping -n 1 -w %seconds% 1.1.1.1 > nul
goto check_one
:: First process complete
:complete_one
echo.
echo The %app1% process has finished!
echo.
echo Starting the %app2% process...
START /WAIT %app2%
:: Second loop check
:check_two
cls
set errorlevel=
tasklist /fi "imagename eq %app2%" | find /i "%app2%"> NUL
if /i %errorlevel% GTR 0 goto complete_two
echo.
echo The %app2% process is running!
echo.
echo Will check again in a few seconds.
echo.
ping -n 1 -w %seconds% 1.1.1.1 > nul
goto check_two
:: Second process complete
:complete_two
echo.
echo The %app2% process has finished!
pause
阅读使用和注释的部分是什么编辑。
如果@LotPings不正则改变app1=noppack.exe
到app1=LEProc.exe
。
希望这会有所帮助!
=)
是的!这是我需要的。尽管如此,我不得不严重截断它;我不需要第二个应用程序部分。你看到我的批处理文件中的下几行不会运行一个新的应用程序,他们实际上删除了'NOPPack'已经(已经打包好)('data'和'script')的2个文件夹,并将生成的NOP文件重命名为一个可释放的名字。显然,我不想这样做,直到'Noppack'完成它的事情。看到我实际上最终使用的线路的OP。 –
它看起来像LEproc.exe衍生另一个进程。
然后它会返回并且在您想知道Noppack.exe何时完成的情况下无法等待LEproc.exe。
你应该和任务列表/ PsList将和循环(有延迟),如果nopppack.exe仍在运行检查。
我从哪里得到这些信息? –
@GeorgeHovhannisian [任务列表](https://ss64.com/nt/tasklist.html)是windows的一部分。 – Stephan
tasklilst是Windows的一部分,[pslist](https://docs.microsoft.com/en-us/sysinternals/downloads/pslist)请参阅[aphoria的评论]中的链接(https://stackoverflow.com/questions/ 45934393/batch-file-wait-for-program-with-complex-command-line-finish/45938425?noredirect = 1#comment78835018_45934393) – LotPings
不一无所知'LEProc.exe',但'runas'将产生一个新的CMD会话起始于'%SYSTEMROOT%\ System32'。所以我最初的猜测不是依靠'%〜dp0'。完全限定exe和数据文件的所有路径。 – elzooilogico
'LEProc'只是区域模拟器,需要在韩文区域运行'noppak.exe'。这不是拖延... –
我完全坚持晋级路径'开始 “”/等待CMD/C^“” C:\ some_folder \ LEProc.exe “-runas ba954abf -...- 4b6d90aed470” C:\您的文件夹\ another_folder \ noppack.exe” “C:\您的文件夹\什么\数据脚本”^“' – elzooilogico