user1863359
user1863359

Reputation: 317

Waiting for process until it terminate to run an other

I have an executable file that generate me reports in the current folder, I want that after generating the report to move it to another folder :

start /WAIT /B "" "C:\Generator.exe"
for /R "C:\" %%f in (*.xlsx) do copy  "%%f" "C:\ABC"
Del /Q "C:\*.xlsx"

the problem is that The second and third lines in the batch files run before the first line terminate (it show me a message that the .xlsx file does not exist which is quite normal becaus the .exe is still running)

Upvotes: 1

Views: 733

Answers (2)

Siddharth Sinha
Siddharth Sinha

Reputation: 41

c:\generator.exe
:sleeping
tasklist /FI "IMAGENAME eq generator.exe" 
if "%ERRORLEVEL%"=="0" goto sleeping
for /R "C:\" %%f in (*.xlsx) do copy  "%%f" "C:\ABC"
Del /Q "C:\*.xlsx"
exit

There is a sleeping till generator.exe stops and then proceeds to next lines in your code ... the errorlevel checks if the process is running (status = 0) so till the time the errorlevel becomes 1 the loop goes on.

Sid

Upvotes: 1

Endoro
Endoro

Reputation: 37569

try this:

C:\Generator.exe
for /R "C:\" %%f in (*.xlsx) do copy  "%%~f" "C:\ABC"
Del /Q "C:\*.xlsx"

Upvotes: 2

Related Questions