2016-08-13 54 views
0

我想強制命令行等待他自己的進程,因爲這個進程app.exe必須完成,並且需要一些時間。我使用人工超時來防止腳本關閉,因爲如果我將超時設置錯誤,那麼app.exe會給出錯誤的結果。我有正確的估計超時問題。強制批處理文件等待他自己的進程

我讀了一些關於options/w和/ k的內容,但我不知道它在哪裏插入。 也許等待進程會是很好的解決方案,但我不知道該怎麼做。 代碼如下:

( 
@echo instruction1 to app.exe 
@echo instruction2 to app.exe 
@echo instruction3 to app.exe 
@echo instruction4 to app.exe 
timeout 3 
) | app.exe > out.txt 

這個腳本是由C語言編寫另一個應用名爲++而不是從APP.EXE。我有Windows 7 其運行腳本行:

system("script.bat");

回答

0

您可以使用開始命令使批處理腳本等待本身

@echo off 

if /I "%~1" EQU "runme" goto %~1 

start "" /B /WAIT cmd /c "%~s0 runme %*" 

exit /B 

:runme 

( 
@echo instruction1 to app.exe 
@echo instruction2 to app.exe 
@echo instruction3 to app.exe 
@echo instruction4 to app.exe 
) | app.exe > out.txt 

timeout 3 

exit /B 

編輯:可能我誤解了你的問題,也許這就是你要求的

start "" /B /WAIT cmd /c "app.exe some_parameter_here" 
start "" /B /WAIT cmd /c "app.exe some_parameter_here" 
start "" /B /WAIT cmd /c "app.exe some_parameter_here" 
... 

start "" /B /WAIT cmd /c "echo some_parameter_here | app.exe" 
start "" /B /WAIT cmd /c "echo some_parameter_here | app.exe" 
start "" /B /WAIT cmd /c "echo some_parameter_here | app.exe" 
... 
相關問題