Execute php script (Windows)
A few days ago I published this thread, and 开发者_JAVA百科it was solved succesfully on Unix.
Now I moved to Windows and I have the same problem.
I need to execute a command from the web application. It must execute a .jar
stored in the system. I looked on Google and found some changes that I needed to do.
The function to execute the command is:
<?php
if($_POST["name"] == "")
echo "name is empty";
else{
$path = $_POST["name"];
//$command = 'DISPLAY=:0 java -jar '.$path'; -> Used in Unix
//$command = 'java -jar ../../../../simulaciones/tanqueCalentamiento.jar';
$command = 'java -jar ..\..\..\..\simulaciones\tanqueCalentamiento.jar';
//system($command);
exec($command);
}
?>
The comments are different options I have tried. $path
is the argument, but decided to put directly the path, to clarify my question:
Do I need a kind of "trick" as I did for Unix?
The one I use:
function _exec($cmd)
{
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, 0,false);
error_log($cmd);
return $oExec == 0 ? true : false;
}
/!\ If your application has an interface, and if you are using vista or 7, your server can't be run as a service!
You're just starting 'java'. That means that the Java executable (java.exe) must exist, and must be able to be executed. Since you don't specify a path, it must be in a directory that is in the %PATH% environment variable.
To test, simply start cmd and type java<enter>
. If java gets executed, you'll know at least you'll have java installed and startable. If it doesn't, check if you have java and specify the correct path to the java executable.
You can also run the .jar
from the command line to see if it works. If it works like this, it is likely to work in PHP too.
In windows vista, 7 (I don't know if in others too), there is a problemm with xampp.
The apache does not stop, doesn't matter what you do, even switch the computer off. At least for me, the solution was:
- Uninstall xamp and reinistall it.
Start/stop it always as administrator:
path\xampp\xampp_start
path\xampp\xampp_stop
Right click: run as administrator.
In this way apache is finished properly, and I can run my command with no probleems anymore
I hope this helps http://drupal.org/node/224342
精彩评论