PHP exec()
executes a server-side command, since it is not a client-side language.
Running a JAR through the browser
To run a jar in the browser, as you wish, what I would indicate is to use a applet , as seen in that answer and call it by javascript, as in the following example:
<applet name="myapp" archive="myjar.jar" code="com.company.MyApplet"/>
<script>
var result = myapp.foo();
</script>
Running a JAR that is on the client computer by Internet Explorer
Another possibility, after seeing what you wanted from editing the question, is to request, through javascript , have the client run the jar by ActiveXObject
, as can be seen here . The example to run is this:
function RunExe(){
var w = new ActiveXObject("WScript.Shell");
var myJar = 'C://WindowJar.jar'; //exemplo
w.run(myJar);//Roda o jar
return true;
}
If you want to work on a return of the executed file, you can use the following example:
function RunExe(){
var w = new ActiveXObject("WScript.Shell");
var myJar = 'C://WindowJar.jar'; //exemplo
var ex = w.run(myJar);//Roda o jar
var ret = "";
//lê a saída do jar
while (!ex.StdOut.AtEndOfStream) {
ret += ex.StdOut.ReadLine();
}
//Dá um alert no retorno
alert(ret)
return true;
}
Running a JAR that is on the client computer using protocols
Another alternative, not indicated for security reasons, is to use URL protocol , which means to tinker with the records of the target machine. Under this example , you can achieve this goal as follows:
Create a personized protocol
[HKEY_CLASSES_ROOT\protocolname]
@="URL: descricao"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\protocolname\shell]
[HKEY_CLASSES_ROOT\protocolname\shell\open]
[HKEY_CLASSES_ROOT\protocolname\shell\open\command]
@="\"C:\Path to\Jar\myJar.jar\" %1"
Using a reference tag in HTML
<a href="protocolname:parameter-value">link</a>
However, the following can be removed from the above documentation:
Security Alert Applications that handle URL protocols must consider how to respond to malicious data. Because handler applications can receive data from untrusted sources, the URL and other parameter values passed to the application may contain malicious data that attempts to exploit the handling application.
Free translation:
Security Alert Applications that handle URL protocols should consider how to respond to malicious data. Because the application handler may receive data from untrusted sources, the URL or other parameter values passed to the application may contain malicious data that tries to exploit the manipulated application.
So, if it is not strictly necessary to use another browser, I suggest using Internet Explorer with ActiveXObject
, because it is simpler and less dangerous than creating a custom protocol.