Using PHP's
execfunction to perform
shell, many commands can be executed, but there is a problem with executing Java programs.
[testshell.php] as follows:
Java file is also very simple, is a test file, output HelloWorld, and write to the file.
In addition I use php direct execution of this file, such as Next, success, no problem:
$ php testshell.php
But in the browser to execute this PHP file, no response.
Start guessing is a write permission problem, but it also writes a python test:
file("output.txt").write("测试\n")
Then testshell.php instead:
$str="python a.py";exec($str,$output,$retnruVal);print_r($output);
This is also successful, so you do not know where the problem is-please advise AH.
Procedures attached to A.java:
import java.io.File;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileInputStream;import java.io.FileWriter;public class a{public static void main (String[] args) { try{ File writename = new File("output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件 writename.createNewFile(); // 创建新文件 BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("我会写入文件啦\r\n"); // \r\n即为换行 out.flush(); // 把缓存区内容压入文件 out.close(); // 最后记得关闭文件 }catch(Exception e){ e.printStackTrace(); }}}
a.javachange, add an output, the result can be output, that is, can be executed System.out.println but subsequent code can not be executed, the feeling is not a permission problem ah.
public static void main (String[] args) { try{ String a = "hello"; System.out.println(a); File writename = new File("output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件 writename.createNewFile(); // 创建新文件 BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("我会写入文件啦\r\n"); // \r\n即为换行 out.flush(); // 把缓存区内容压入文件 out.close(); // 最后记得关闭文件 }catch(Exception e){ e.printStackTrace(); }}
Reply content:
Using PHP exec functions to execute shell , a lot of commands can be executed, but the implementation of Java program has a problem.
[testshell.php] as follows:
Java file is also very simple, is a test file, output HelloWorld, and write to the file.
In addition I use php direct execution of this file, such as Next, success, no problem:
$ php testshell.php
But in the browser to execute this PHP file, no response.
Start guessing is a write permission problem, but it also writes a python test:
file("output.txt").write("测试\n")
Then testshell.php instead:
$str="python a.py";exec($str,$output,$retnruVal);print_r($output);
This is also successful, so you do not know where the problem is-please advise AH.
Procedures attached to A.java:
import java.io.File;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileInputStream;import java.io.FileWriter;public class a{public static void main (String[] args) { try{ File writename = new File("output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件 writename.createNewFile(); // 创建新文件 BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("我会写入文件啦\r\n"); // \r\n即为换行 out.flush(); // 把缓存区内容压入文件 out.close(); // 最后记得关闭文件 }catch(Exception e){ e.printStackTrace(); }}}
a.javachange, add an output, the result can be output, that is, can be executed System.out.println but subsequent code can not be executed, the feeling is not a permission problem ah.
public static void main (String[] args) { try{ String a = "hello"; System.out.println(a); File writename = new File("output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件 writename.createNewFile(); // 创建新文件 BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("我会写入文件啦\r\n"); // \r\n即为换行 out.flush(); // 把缓存区内容压入文件 out.close(); // 最后记得关闭文件 }catch(Exception e){ e.printStackTrace(); }}
I don't know if there is any specific return information, but from my inference, it has nothing to do with the file path.
is the environment variable in Java correct? Try the Java full path execution.
has been resolved. Permissions issues. Www-data is the default user no write file permission ... The pit.