2

Here is the task:

I have a windows .cmd file that basically navigates to a given directory and runs a given Java program. I can directly run this file and it works just as I expect it to. However, I would like to run it from within a locally hosted php webpage and I would also like for this to be run asynchronously so that my webpage can make use of the data being produced by the java program.

I have tried several things that I was able to find online, including this proposed solution: PHP exec() as Background Process (Windows Wampserver Environment) but nothing seems to work for me.

I was under the impression that a function like this:

<?php 
function runAsynchronously($path) { 
    $WshShell = new COM("WScript.Shell"); 
    $oExec = $WshShell->Run($path, 7, false); 
    unset($WshShell,$oExec); 
} 
?>

when called with

runAsynchronously('notepad');

(for example), should open notepad and continue to run the php scrip from where it was called. However, nothing seems to happen when I do that. Any suggestions? Beware that I am not experienced with php at all, so I could be unknowingly doing something very stupid :)

Community
  • 1
  • 1
Everaldo Aguiar
  • 4,016
  • 7
  • 26
  • 31
  • Invoke `start` instead, which will start your specified program and then return immediately without blocking. – Marc B Nov 16 '11 at 20:54
  • @Marc B Sorry if I'm misinterpreting, but do you mean it as `exec('start notepad');` ? That still blocks. Calling the function with `runAsynchronously('start notepad');` gives me an error – Everaldo Aguiar Nov 16 '11 at 20:57

0 Answers0