geevim Posted June 24, 2010 Share Posted June 24, 2010 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 More sharing options...
geevim Posted June 24, 2010 Author Share Posted June 24, 2010 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/#findComment-1076484 Share on other sites More sharing options...
mentalist Posted June 24, 2010 Share Posted June 24, 2010 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"; } Link to comment https://forums.phpfreaks.com/topic/205718-how-to-capture-java-outputs-in-php/#findComment-1076515 Share on other sites More sharing options...
geevim Posted June 24, 2010 Author Share Posted June 24, 2010 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 Link to comment https://forums.phpfreaks.com/topic/205718-how-to-capture-java-outputs-in-php/#findComment-1076524 Share on other sites More sharing options...
mentalist Posted June 24, 2010 Share Posted June 24, 2010 Yes, basically any shell commands... For popen or any other php functions start with the manual... http://uk3.php.net/manual/en/function.popen.php Link to comment https://forums.phpfreaks.com/topic/205718-how-to-capture-java-outputs-in-php/#findComment-1076528 Share on other sites More sharing options...
geevim Posted June 24, 2010 Author Share Posted June 24, 2010 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] Link to comment https://forums.phpfreaks.com/topic/205718-how-to-capture-java-outputs-in-php/#findComment-1076529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.