samedi 3 janvier 2015

PHP "Output file write error" with shell_exec and stdin (|)



php -a
echo shell_exec('djpeg image.jpg | pamfile');


result:



Output file write error --- out of disk space?
stdin: PPM raw, 500 by 373 maxval 255


(djpeg converts a jpeg to PPM and writes to standard output, and pamfile reads this data and tells info about the file. Second line is normal output of the pamfile, but I have no idea where the first line is coming from!).


On the other hand, if I write to a file, i.e. shell_exec('djpeg image.jpg > temp_file.pam'); and then read from file shell_exec('pamfile temp_file.pam'); then no "output file write error" is displayed! even if I use @ does not help. I'm not sure why this happens! Although script works, it's a bit annoying to see the "output file write error" every time. I suspect it's due to the usage of | which writes to memory or something like that. If I call the same code from a php file run on a webserver, the error is not displayed, but I think it does happen, although it's no really part of output.


The temp file size is not big, it's max 500kb. I tried ini_set('memory_limit','512M'); but it does not help.



Aucun commentaire:

Enregistrer un commentaire