1

Possible Duplicate:
Execute external program from Java

Is it possible to Run a php script from a java class. My project is a struts2 frame work web application. Its purely a java webapp We use a php script to run some daily cron jobs. It was written in php by an ex-employee. Is there a way to run the php script from the javaclass?

Community
  • 1
  • 1
Sangram Anand
  • 10,156
  • 22
  • 67
  • 102

1 Answers1

1

Since you're essentially running a command line script, you could use Runtime.getRuntime().exec. Here's a page with a plethora of examples: http://www.rgagnon.com/javadetails/java-0014.html.

If the PHP script is externalized as a web page, you could use Java's URLConnection to call the page so it runs. Documentation: http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html

atrain
  • 9,035
  • 1
  • 35
  • 40