Trying to run a jar from PHP

前端 未结 3 1839
梦毁少年i
梦毁少年i 2021-01-28 08:16

After reading some of the posts in this website related to exactly the same issue I\'ve got, I found that none of them were giving me a successful result:

How to run a j

相关标签:
3条回答
  • 2021-01-28 08:21

    You have to do something like this:

    //REPLACE THIS PATH WITH THE REAL JAVA PATH
    $handle = popen(`"C:\\Program Files (x86)\\Java\\jre7\\bin\\java.exe arguments"`, "r"));
    //You can read with $read = fread($handle, 2096)
    pclose($handle);
    

    exec will not work on Windows (for "external" executables) and in most cases you'll have to provide the full path to Java.

    0 讨论(0)
  • 2021-01-28 08:28

    You can check with shell_exec, system() and other function pctl function as well. These functions might be disabled, so before executing check them or you can use this as well

    function execInBackground($cmd) { 
        if (substr(php_uname(), 0, 7) == "Windows"){ 
            pclose(popen("start /B ". $cmd, "r"));  
        } 
        else { 
            exec($cmd . " > /dev/null &");   
        } 
    } 
    

    More detail found here.

    0 讨论(0)
  • 2021-01-28 08:34

    This is not a straight answer, but if calling java from Php does not work under any circumstances, you can also run jar files from Python scripts. I mean Php --> Python --> jar.

    Calling Python scripts from Php always works for me.

    This post helped me in the past:

    Python: How can I execute a jar file through a python script

    0 讨论(0)
提交回复
热议问题