Python-php calls the shell command: exec ('Java-jara. jar') is not executed.

Source: Internet
Author: User
Execute shell using the exec function of php. many commands can be executed, but there is a problem with executing java programs. [Testshell. php] is as follows: {code...} the java file is also very simple. it is a test file that outputs helloworld and writes it to the file. In addition, I use php to directly execute this file... execFunction execution shell, Many commands can be executed, but there is a problem with executing java programs.
[Testshell. php] is as follows:


  

The java file is also very simple. it is a test file that outputs helloworld and writes it to the file.
In addition, I usephpDirectly execute the file as follows:

$ php testshell.php

However, this php file is not reflected when it is executed in the browser.
I started to guess that it was a write Permission problem, but I wrote anotherpythonTest:

File ("output.txt"). write ("test \ n ")

Then change testshell. php:

$str="python a.py";exec($str,$output,$retnruVal);print_r($output);

This is also a success, so I don't know where the problem is-please advise.
Appendix a. java program:

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"); // relative path, if no output exists, a new output is created. Txt file writename. createNewFile (); // create a new file BufferedWriter out = new BufferedWriter (new FileWriter (writename); out. write ("I will write the file \ r \ n"); // \ r \ n is a line break out. flush (); // Press the content in the cache area into the file out. close (); // close the file} catch (Exception e) {e. printStackTrace ();}}}

Seta.javaChanged. an output is added, and the result can be output, that is, it can be executed.System.out.printlnHowever, the subsequent code cannot be executed, and it does not feel like a Permission problem.

Public static void main (String [] args) {try {String a = "hello"; System. out. println (a); File writename = new File ("output.txt"); // relative path. if not, create a new output. Txt file writename. createNewFile (); // create a new file BufferedWriter out = new BufferedWriter (new FileWriter (writename); out. write ("I will write the file \ r \ n"); // \ r \ n is a line break out. flush (); // Press the content in the cache area into the file out. close (); // close the file} catch (Exception e) {e. printStackTrace ();}}

Reply content:

PhpexecFunction executionshell, Many commands can be executed, but there is a problem with executing java programs.
[Testshell. php] is as follows:


  

The java file is also very simple. it is a test file that outputs helloworld and writes it to the file.
In addition, I usephpDirectly execute the file as follows:

$ php testshell.php

However, this php file is not reflected when it is executed in the browser.
I started to guess that it was a write Permission problem, but I wrote anotherpythonTest:

File ("output.txt"). write ("test \ n ")

Then change testshell. php:

$str="python a.py";exec($str,$output,$retnruVal);print_r($output);

This is also a success, so I don't know where the problem is-please advise.
Appendix a. java program:

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"); // relative path, if no output exists, a new output is created. Txt file writename. createNewFile (); // create a new file BufferedWriter out = new BufferedWriter (new FileWriter (writename); out. write ("I will write the file \ r \ n"); // \ r \ n is a line break out. flush (); // Press the content in the cache area into the file out. close (); // close the file} catch (Exception e) {e. printStackTrace ();}}}

Seta.javaChanged. an output is added, and the result can be output, that is, it can be executed.System.out.printlnHowever, the subsequent code cannot be executed, and it does not feel like a Permission problem.

Public static void main (String [] args) {try {String a = "hello"; System. out. println (a); File writename = new File ("output.txt"); // relative path. if not, create a new output. Txt file writename. createNewFile (); // create a new file BufferedWriter out = new BufferedWriter (new FileWriter (writename); out. write ("I will write the file \ r \ n"); // \ r \ n is a line break out. flush (); // Press the content in the cache area into the file out. close (); // close the file} catch (Exception e) {e. printStackTrace ();}}

I don't know if there is any specific response information, but from my inference, it is irrelevant to the file path.

Is the java environment variable correct. Try to use the full java path for execution.

The permission issue has been resolved. Www-data is a default user with no permission to write files... Pitfall

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.