shell_exec() 函数表现异常
shell_exec() function is behaving strangely
我试图通过 php 和 shell_exec() 运行 一个 java 文件的行为很奇怪。
<?php
shell_exec("javac Driver.java");
echo shell_exec("java Driver");
?>
此代码导致 java 文件的内容显示在我的网络浏览器中,我不知道为什么,因为我是 php 的新手。任何见解将不胜感激。
这可能是因为编译过程中出现问题,因此没有程序可执行,也可能是因为输出重定向。
解决问题。
Step 1 : Compile the java program from commandline and make sure java program-name command is giving desired output. Also use absolute path to java file whenever required
Step 2 : Then if that is correct you should check if redirection of output is correct. system.out.println may not be using stderr . Try adding adding 2>&1 after your command.
Step 3 : Check your classpath.
请看下面的link。它有解决您面临的相同问题的方法。
Running a Java File from PHP
我试图通过 php 和 shell_exec() 运行 一个 java 文件的行为很奇怪。
<?php
shell_exec("javac Driver.java");
echo shell_exec("java Driver");
?>
此代码导致 java 文件的内容显示在我的网络浏览器中,我不知道为什么,因为我是 php 的新手。任何见解将不胜感激。
这可能是因为编译过程中出现问题,因此没有程序可执行,也可能是因为输出重定向。
解决问题。
Step 1 : Compile the java program from commandline and make sure java program-name command is giving desired output. Also use absolute path to java file whenever required
Step 2 : Then if that is correct you should check if redirection of output is correct. system.out.println may not be using stderr . Try adding adding 2>&1 after your command.
Step 3 : Check your classpath.
请看下面的link。它有解决您面临的相同问题的方法。
Running a Java File from PHP