2017-08-29 81 views
1

我需要這個完成後才能運行此命令在批處理批處理文件等待程序複雜的命令行完成

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 
[...] 
+0

不一無所知'LEProc.exe',但'runas'將產生一個新的CMD會話起始於'%SYSTEMROOT%\ System32'。所以我最初的猜測不是依靠'%〜dp0'。完全限定exe和數據文件的所有路徑。 – elzooilogico

+0

'LEProc'只是區域模擬器,需要在韓文區域運行'noppak.exe'。這不是拖延... –

+0

我完全堅持晉級路徑'開始 「」/等待CMD/C^「」 C:\ some_folder \ LEProc.exe 「-runas ba954abf -...- 4b6d90aed470」 C:\您的文件夾\ another_folder \ noppack.exe」 「C:\您的文件夾\什麼\數據腳本」^「' – elzooilogico

回答

1

我沒有測試過這一點,但也許這可以幫助..

@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.exeapp1=LEProc.exe

希望這會有所幫助!

=)

+0

是的!這是我需要的。儘管如此,我不得不嚴重截斷它;我不需要第二個應用程序部分。你看到我的批處理文件中的下幾行不會運行一個新的應用程序,他們實際上刪除了'NOPPack'已經(已經打包好)('data'和'script')的2個文件夾,並將生成的NOP文件重命名爲一個可釋放的名字。顯然,我不想這樣做,直到'Noppack'完成它的事情。看到我實際上最終使用的線路的OP。 –

2

它看起來像LEproc.exe衍生另一個進程。
然後它會返回並且在您想知道Noppack.exe何時完成的情況下無法等待LEproc.exe。

你應該和任務列表/ PsList將和循環(有延遲),如果nopppack.exe仍在運行檢查。

+0

我從哪裏得到這些信息? –

+0

@GeorgeHovhannisian [任務列表](https://ss64.com/nt/tasklist.html)是windows的一部分。 – Stephan

+1

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