Page 1 of 1

command-line tool identify with popen in php cause problems

Posted: 2009-07-24T07:00:43-07:00
by toxicbrain
hello,

i hope i can describe my problem. i use the command-line tool identify to get information about some pdf-files. i use the following php-code:

$handle = popen("identify some_file.pdf", "r");
$read = fread($handle, 2048);
pclose($handle);

as a result i only get an error like Error /undefined. and yes, the file exists. but if i a try this command on a shell command line, i get all the information. everything is fine. did i missed something? sorry for my bad english and thanks for your help.
txb

installed versions:
- ImageMagick 6.4.5 2008-11-13 Q16
- php Version 5.2.6

Re: command-line tool identify with popen in php cause problems

Posted: 2009-07-24T09:58:26-07:00
by magick
A PHP or shell environment may be very different from your command line environment. Try using absolute paths. Instead of identify, try /usr/local/bin/identify. Edit delegates.xml and change "gs" to "/usr/local/bin/gs".

Re: command-line tool identify with popen in php cause problems

Posted: 2009-07-24T10:15:24-07:00
by fmw42
Not sure if this is relevant to your API, but you may need to add 2>&1 to your command in your API. see something similar to what is show in viewtopic.php?f=1&t=13725 for PHP

Re: command-line tool identify with popen in php cause problems

Posted: 2009-07-26T23:15:01-07:00
by toxicbrain
fmw42 wrote:Not sure if this is relevant to your API, but you may need to add 2>&1 to your command in your API. see something similar to what is show in viewtopic.php?f=1&t=13725 for PHP
yes, i already tried this. but it's cause the same error. anyway for your answer, thanks.

Re: command-line tool identify with popen in php cause problems

Posted: 2009-07-27T00:29:19-07:00
by Bonzo
Tried it on my XAMPP server ( php 5.2.9 ) and it works OK and so there must be something wrong with your setup - no idea what it could be though !
As magic says its probably something to do with paths

Code: Select all

<?php
$handle = popen("identify 310509.pdf", "r");
$read = fread($handle, 2048);
pclose($handle);
echo $read;
?>
// Output
310509.pdf PDF 595x842 595x842+0+0 16-bit DirectClass 1.433mb

Re: command-line tool identify with popen in php cause problems

Posted: 2009-07-27T00:32:16-07:00
by toxicbrain
magick wrote:A PHP or shell environment may be very different from your command line environment. Try using absolute paths. Instead of identify, try /usr/local/bin/identify. Edit delegates.xml and change "gs" to "/usr/local/bin/gs".
thats it! now it works perfectly. thanks a lot.