Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exec Function 1

Status
Not open for further replies.

stefanbrown

Technical User
Mar 5, 2001
1
GB
I have a PHP page that i would like to use to execute a java program.

The java program accesses a mysql database and takes three arguments.

I would like to know how to use the exec or system function in PHP to execute a java program taking three arguments.

Any ideas??

Thanks
 
It would most likely be exactly as you describe it:

exec("/path/to/executable argument1 argument2 argument3");

or

exec("/path/to/executable $argument1 $argument2 $argument3");

If there are any environment variables to be set, I'm not sure, but I believe you can also set them just by using exec(), as in

exec("VAR=value; export VAR");

You can see the existing environment variables available to PHP by viewing the output of phpinfo(); in a PHP page.

The real question is do you want to return any data directly into your PHP script from the Java program. If the return is in standard output mode, then you could do this with the Backtick Operator ( as in

$data_return = '/path/to/executable argument1 argument2 argument3';

Of course its up to you to then turn the data into something useful inside PHP, since the standard output will just be in ASCII text format. (maybe some regex work ahead...;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top