views:

137

answers:

2

I have a java program that generates an HTML file. The Java program takes two input parameters: file1 and file2, the output file is specified by the "--file=".

When executed from the command line (UNIX, Mac OS 10.6.2) it looks like this:

"java -jar program.jar http://my.testsite.com/test1.html http://my.testsite.com/test2.html --file=/path/to/jar/new_file_1274119954.html

Executing the program form the command line generates the file "new_file_TIEMSTAMP.html"

Now I want execute this same line form PHP so I created the following script:



$file1 = 'http://my.testsite.com/test1.html';
$file2 = 'http://my.testsite.com/test2.html';
$newFile = '/path/to/jar/new_file_'.time().'.html';


system("java -jar program.jar $file1 $file2 --file=$newFile");

$handle = fopen($newFile, "r");
$output = fread($handle, filesize($newFile));

echo "$output";

Like you can see, I am not really interested in the console output, but rather in the file that is generated by the program.

I have also use the following calls to execute the console command but neither of them works when executing this PHP script from my browser.

I am not sure if there is some special setting that I need to enable in my php.ini, or is something I am doing wrong, but I am not sure what to do now.

Your help is appreciated

PD:

One error message I do get when using the system call is the following: javax.xml.transform.TransformerException: org.xml.sax.SAXException: setResult() must be called prior to startDocument().

A: 

I really don't know much about PHP, but is it possible that when you do the system("java -jar program.jar $file1 $file2 --file=$newFile") call, it isn't evaluating the value of $file1 and $file2, so you are asking it to find a file named $file1, instead of test1.html ?

Instead, I think you want something like

$cmd = "java -jar program.jar " . $file1 . " " . $file2 . "--file=" . $newFile;
system($cmd);
gregcase
+1  A: 

Well, the Java exception tells us there is an XML exception in there, so maybe start with seeing if your source file is valid? It's hard to tell from here what the Java app does.

Also, I'd have a look to see if apache or the PHP user has permission to execute the Java app, and create files.

Good luck.

Kevin Sedgley
It was permissions, such a simple thing!Thank you
Onema