Jump to content

How to Capture Java outputs in PHP ?


geevim

Recommended Posts

Hi,

 

I am executing a  java program using system command in PHP. It produces two ouput files.  One with *.att extension and other with *.arff extension. I just need one of them with the extension *.arff to process further. How can I capture the output in a variable???

ie..something like $name.arff is it possible to do this way??? Stuck up with this..!!!

 

$name = "user.sdf";
$fh = fopen("$name", "r+");
if($fh==false)
    die("unable to create file");

if (file_exists("$name")) {
  echo "$name";
system("/usr/java/jdk1.6.0_16/bin/java -jar -Xmx512M ODDescriptors.jar -f $name -l KI");

 

 

Link to comment
https://forums.phpfreaks.com/topic/205718-how-to-capture-java-outputs-in-php/
Share on other sites

Hi,

 

I am executing a  java program using system command in PHP. It produces two ouput files.  One with *.att extension and other with *.arff extension. I just need one of them with the extension *.arff to process further. How can I capture the output in a variable???

ie..something like $name.arff is it possible to do this way??? Stuck up with this..!!!

 

$name = "user.sdf";
$fh = fopen("$name", "r+");
if($fh==false)
    die("unable to create file");

if (file_exists("$name")) {
  echo "$name";
system("/usr/java/jdk1.6.0_16/bin/java -jar -Xmx512M ODDescriptors.jar -f $name -l KI");

Instead of using 'system', have a look at 'popen' or maybe 'proc_open'.

 

Here's an example of a function which captures output from an executed command:

function exe($cmd){
$aret=array();
if(!$f=popen($cmd,'r')){return null;}
while(!feof($f)){
	$o=fgets($f,1024);
	//print $o."<br />\n";
	$aret[]=$o;
}
pclose($f);
return $aret;
}

$a=exe('ls -al');
foreach($a as $e){
print $e."<br />\n";
}

Hi,

 

Thanks for your reply...I am having a look as how to use popen function..

I am a newbie.....can you please suggest me some simple fucntions???

Okay.. :( Can I replace java command in the place of exe('ls -al') in your example???

will it work this way???

 

thanks

Hi,

 

I was able to run the java program using "popen" . I  got the "output comments"  (i am enclosing the snapshot)

but what about "output files"?? I had the same problem while running the system command

 

ie..after i run the program it generates two files (*.arff and *att extensions)

I need to access *.arff usign a variable??

Can you please tell which variables are assigned to "output files"?

 

 

Thanks

 

 

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.