1

How can you run multiple exec instances from a for loop and run them separately (i.e. not have one dependent on another finishing before starting another)? I have the following code which is hopefully self explanatory:

for ($i = 0;$i < 5;$i++){
    exec('START '.$path.' '.PATH.'spawn.php "'."$type,$core".'"');
}

I have looked at php in background exec() function but it isn't a duplicate as I am using the START command and adding an & did not fix it.

I have tried /B as an option but additionally this didn't work - it just ran it in the background.

4
  • What OS are you using? Commented Sep 2, 2015 at 15:01
  • Windows 2008 R2 SP1 :) Commented Sep 2, 2015 at 15:04
  • Okey the reason the & did not work is because that's for a Unix OS. Do you want the processes the run in parallel or one after the other? Commented Sep 2, 2015 at 15:14
  • All at the same time - in parallel. Is that possible? Commented Sep 2, 2015 at 15:16

1 Answer 1

1

Under windows you will need to do it a bit differently.

$runCommand = 'calc.exe';
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($runCommand, 7, false);

This should help explain it http://www.somacon.com/p395.php

https://www.php.net/manual/en/function.exec.php#43917

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

1 Comment

Brilliant. Although I still need to tweak my code WScript.Shell through COM worked great. Thanks

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.