Jump to content
Larry Ullman's Book Forums

Outputting Stdout From Exec Call


Recommended Posts

Like I said in a previous post I'm using the Zend_Lucene article from your blog to index the text I'm extracting from a number of PDFs. I've managed to get XPDF installed on my local MAMP server and can convert PDF's to text files using this line:

 

exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf " . $pdf_filename . "1.txt");

 

From the docs I've found here it says if you supply '-' as the text file name the text will be sent to STDOUT. Should this not mean I can assign that value to a variable like:

 

$text = exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf -");

 

or print it out using:

 

echo exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf -");

 

Because neither of them seem to work yet converting to a text file does? Do I need to do something else to gain access to the SDTOUT?

 

If you fancy writing a Linux and Apache book I'd buy it! I seem to only be half a LAMP stack developer :(

Link to comment
Share on other sites

Thanks for that Larry I had looked at the manual already but got confused by this example:

 

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

 

Hence why I tried to just echo/assign the result of exec - all working now after a closer inspection thanks.

Link to comment
Share on other sites

exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf " . $pdf_filename . "1.txt");

 

I haven't tried this, but try adding more parameters to the function.

 

<?php

$command = "/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 ";

exec ($command . $pdf_filename . ".pdf " . $pdf_filename . "1.txt", $return_array, TRUE);

foreach ($return_array as $output) {
echo $output;
}

?>

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...