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 :)

2
  • Invoke start instead, which will start your specified program and then return immediately without blocking. Commented Nov 16, 2011 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 Commented Nov 16, 2011 at 20:57

0

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.