我试图通过php运行一个java文件,而shell_exec()表现得很奇怪。
<?php
shell_exec("javac Driver.java");
echo shell_exec("java Driver");
?>
此代码导致java文件的内容显示在我的Web浏览器中,我不知道为什么我是php的新手。任何见解都将不胜感激。
答案 0 :(得分:1)
可能是因为编译过程中存在问题,因此无法执行程序,也可能是因为输出重定向。
解决问题。
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.
请查看下面的链接。它可以解决您面临的同一问题。