Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Batch file parallel processing

Nov 24, 2010 12:30AM PST

Hi,

I'm running 64b Win7. I have a batch file (.bat) that I use to shut the machine down each night, that optionally backs up data and then which calls CCleaner. After CCleaner finishes the system shuts down.

Everything works fine. But here's what I want to do. I want to start another program when the script opens, have it run in parallel to the backup and cleaning operation, and have its completion mutually critical, with the backup/cleaning operations, to the machine shutting down.

IOW, I want to parallel process, but I want the final shut down to be dependent on both processes completing. I don't want the system to shut down until both are finished.

It's a logical problem that I haven't been able to find a batch tool to solve yet.

Thanks,
p.

Discussion is locked

- Collapse -
more detail
Nov 24, 2010 12:34AM PST

I should have mentioned what I'm currently doing. I call the initial program via the Start command. That gets it going while the batch logic continues. The problem is that the machine will shut down even if the first program isn't finished.

- Collapse -
The problem is that the machine will shut down even if the f
Nov 24, 2010 1:05AM PST

The problem is that the machine will shut down even if the first program isn't finished.

Odd. Wouldn't your batch check to see if the job is done? EXAMPLE.

ECHO RUNNING > RUNNING.TXT
START other job
Do things.
Done doing things.
IF EXIST RUNNING.TXT Sleep and check again

The other job when down deletes RUNNING.TXT to flag to the other batch job it's done.

It seems your scripts need a little more logic.
Bob

- Collapse -
For some reason each post needs a new title
Nov 24, 2010 10:52AM PST

Bob, I don't understand what's happening in the echo command of your example. I tried this trivial example:

ECHO RUNNING > RUNNING.TXT
START "" notepad.exe
"c:\users\paul\desktop\us time zone map.gif"
IF EXIST RUNNING.TXT timeout /t 5 /nobreak > NUL
taskkill /IM notepad.exe

Killing the second process triggers ending the batch, even with the Start process still running. Killing the Start process doesn't affect the batch. So this doesn't achieve the mutual criticalness I'm looking for.

Thanks,
p.

- Collapse -
Close but.
Nov 24, 2010 11:33AM PST

I'm guessing you want to loop around until the other app has finished. Something like

:loopy
delay so long
if exist running.txt goto loopy

Sorry if I don't write the exact code. Just sharing the concept.
Bob

- Collapse -
Success
Nov 24, 2010 10:33PM PST

Ok, thanks. I got it working using a similar technique.

p.