Wojciech Szabowicz
Wojciech Szabowicz

Reputation: 4198

Deleting file after progeam execution in batch

I am having a simple question, having simple batch script:

for /l %%x in (1, 1, 3) do start /wait c:\some.exe -verbose c:\someLog.txt del c:\someLog.txt 

after each execution file creates log, and I want to remove that log before next loop execution, execution works fine but when I add del command its having problems, it looks like log is being deleted to early.

Is there a possible way to delay del command ??

Upvotes: 0

Views: 363

Answers (1)

Squashman
Squashman

Reputation: 14320

When running multiple command I usually nest them for readability.

for /l %%x in (1, 1, 3) do (
    start /wait c:\some.exe -verbose c:\someLog.txt 
    del c:\someLog.txt 
)

You could probably do it this way as well

for /l %%x in (1, 1, 3) do (start /wait c:\some.exe -verbose c:\someLog.txt &del c:\someLog.txt)

But this does not mean that your executable is actually respecting the WAIT option. Many programs do not. I would just use the exe directly without using START at all.

Upvotes: 3

Related Questions