The exec()
PHP runs a command server-side, since it is not a language client-side.
Running a JAR through the browser
To execute a jar in the browser, as you wish, what I would indicate is to use a applet, as seen in this reply 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’s computer by Internet Explorer
Another possibility, after seeing what you wanted from the issue issue, is to request, through javascript, that the customer turns the jar for 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 some 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’s computer using protocols
Another alternative, not indicated for safety reasons, is to use URL protocols, which means tampering with the records of the target machine. According to this example, it is possible to achieve this objective as follows:
Create a personified 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 may be removed from the abovementioned 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.
In free translation:
Security Alert Applications that manipulate URL protocols should consider how to respond to malicious data. Because the application handler may receive data from unreliable sources, the URL or other parameter values passed to the application may contain malicious data that tries to exploit the manipulated application.
Therefore, if it is not strictly necessary to use another browser, I recommend using Internet Explorer with the ActiveXObject
, for being simpler and less dangerous than creating a custom protocol.
Leaving a link here that may help in the future :)
 http://stackoverflow.com/questions/11922225/how-to-use-php-exec-to-run-jar-with-input-parameters
– user20850
Dude, do the following, play the jar on the client and create a link in the browser to open a page accessing a server installed on the client and makes this server"client" invoke the jar... to searching how to do too and I just got this idea... I haven’t even tried it yet! hopefully it works!
– user21420