1

Got a folder which contains automatically generated batch scripts. For example - a cron job runs a script, grabs all new rows from a database, cURLs to my windows server, writes a batch file to the folder with the specific ID.

I then have a secondary batch file which I need to run all these batch files at once, not sequentially. The reason for this is at any one time, there can be 100 batch scripts in the folder, taking on average 3 minutes each, which is five hours, while testing shows that all 100 are fine running at once, and only takes 5 minutes.

So far I have:

FORFILES /S /P "./batch_files" /M *.bat /C "cmd /c call @file /Q "

Which does loop through all the files, however only runs them sequentially. I was thinking assigning each file name to a variable and using the "&" operator so it would basically be

FORFILES /S /P "./batch_files" /M *.bat /C "cmd /c variable = variable+"&"+@fname /Q "
call variable

But in proper batch file formatting (I suck at CMD).

Also I don't know whether "variable" would be global, as it runs a separate instance of cmd on every forfiles?

1
  • I have tried start, however it does not run the batch file. Commented Jul 28, 2011 at 11:31

3 Answers 3

1

Rather than:

Cmd /C Call @file /Q

use:

Start Cmd.exe /Q /C @file

Start begins a process and returns immediately.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response, unfortunately start didnt seem to run the file correctly when used in FORFILES. I went down the route of using Start in the batch that ran the FORFILES, so PHP inserted a new line for each batch file
I've never tried ForFiles. I've always used the For command. I'm glad you've got it working!
1

You can't. The START command start another process and returns immediately to execute the next line in a Batch file IF AND ONLY IF the executed process is a 32-bits Graphical Windows application. If not, that is the case of CMD.EXE, then START waits for the executed command to end.

1 Comment

Ah ok, well I sorted it by running all batch files at once with a huge list of start /path/to/batch.bat
1

A combination of the above answers should help.

Assuming you are wanting to search the contents of folder batch_files located in the root folder would give the following:

FORFILES /S /P "\batch_files" /M *.bat /C "cmd /C start call @file"
EXIT /B

This worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.