Cannot call antiword from PHP using exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DanSearle
Forum Newbie
Posts: 2
Joined: Wed Feb 16, 2005 6:12 pm
Location: Barcelona, Spain

Cannot call antiword from PHP using exec()

Post by DanSearle »

Hi!

I've set up a site part of which allows ppl to upload docs which I then try to parse to get any plain text out of them - PDF and Word DOC formats.

I have two apps to do this - pdftotext and antiword - and I'm calling them with the PHP command exec()

Both apps are in the same folder, they both read from the same folder, and try to write to a new file in the same folder. Both have the same permissions. PDFTOTEXT works fine, ANTIDOC doesn't.

The only real diff I can see is that PDFTOTEXT allows you to specify an output file, whereas ANTIDOC dumps to the screen by default, so has to be directed (antidoc source.doc > source.txt) to get it to write out to a file.

When called directly from the command line antiword works fine - so the app seems ok.

Does anyone have any idea what might be causing this to fail when called from PHP? I have to have this working next week so am a little desperate for help here!

I'm using a managed server, so I don't have root access.

Cheers!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

exec() wrote:Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.
You can store the stdout data as a php array, which you can write to a file, if need be.
DanSearle
Forum Newbie
Posts: 2
Joined: Wed Feb 16, 2005 6:12 pm
Location: Barcelona, Spain

Post by DanSearle »

I'm not that advanced with linux shell commands - is it the stdout when calling the app dumps output to the screen?

In anycase, I've tried before to capture the output from exec and echo-ing it, but that also failed to produce anything.

Here's the code I'm trying - the PHP script runs from the directory that contains the 'assets' directory that it reads from and writes the files to -

Code: Select all

$strCMD = "../executable/antiword assets/" . $filename . " > assets/" . $filenamebare . ".txt";
$dump = exec($strCMD, $AllOutput, $ReturnValue);
			
echo "<p>strCMD: $strCMD</p>";
echo "<p>dump: $dump</p>";

for($i = 0; $i < count($AllOutput); $i++)&#123;
    echo "<p>AllOutput - " . $i . " - " . $AllOutput&#1111;$i] . "</p>";
&#125;

echo "<p>ReturnValue - " . $ReturnValue . "</p>";
exit;
and here is some example output from that code -
strCMD: ../executable/antiword assets/cv_word_test_61.doc > assets/cv_word_test_61.txt

dump:

ReturnValue - 1
I get the same if I remove the > direct from the antiword command.
Post Reply