How to run a program written in php through a Java program?

I have a program written in php, and I want the program written in Java to run this program and get results from it as needed. Please write a piece of code in java, how to do this, maybe you need some kind of input-output stream to the php interpreter… or something else.

Answer 1, authority 100%

You can use the standard Runtime.exec
.For example:

Process p = Runtime.getRuntime.exec();  
Reader reader = new InputStreamReader(p.getInputStream);//    
PrintWriter writer = new PrintWriter(p.getOutputStream);// 

Answer 2

You can run the code:

try {
  Runtime.getRuntime().exec("php file.php");
} catch (IOException e) {

Before starting, check that the ‘php’ command is available anywhere from the console, or in the exec method, write the path to it.