0

I am using a java file to generate a report. It is located on my local hard disk. When I call it using cmd prompt it produces output. I want to run this java file using php file.

The lines in cmd are

D:\>cd class
D:\>class> java Reportgeneration username password id date

These lines are used to execute the java file, how can I execute this code in a php script

3 Answers 3

1

You can use the exec function in php to execute command line statements and get back results. You could also use system

exec() is for calling a system command, and perhaps dealing with the output yourself. system() is for executing a system command and immediately displaying the output.

Sign up to request clarification or add additional context in comments.

Comments

0

PHP's exec does the trick. Read the manual!

Comments

0

Have a look at string shell_exec (string $cmd) It allowes you to execute a command in your shell and return the output as a string for furter processing in PHP.

<?php
  $output = shell_exec('ls -lart');
  echo "<pre>$output</pre>";
?>

If you have more than one shell command to execute, put them in a .bat file and call teh bat file instead.

Remember that PHP needs the privileges to access the directory and the right to execute.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.