2 years ago
#65926
user17966019
How to deal with CLI programs that break the way that output is supposed to be returned?
All too often, I encounter a crucial but badly designed program that "breaks the output". It doesn't actually return its output to PHP's functions that execute the terminal command, but "force-output" it on the command line, separate from the returned data (which is empty).
For example, pdftotext.exe -v
results in empty return data, but this text (which should be its return data) is outputted:
pdftotext version 4.03 [www.xpdfreader.com]
Copyright 1996-2021 Glyph & Cog, LLC
Doesn't matter if you use the -q
option.
How to force software like this to not "separate-output" what should be its return data? And why/how do they even do this in the first place? I don't get how it's technically possible.
Code example:
var_dump(shell_exec('"C:\Program Files\xpdf-tools-win-4.03\bin64\pdftotext.exe" -v'));
Output:
pdftotext version 4.03 [www.xpdfreader.com]
Copyright 1996-2021 Glyph & Cog, LLC
NULL
php
windows
windows-10
output
command-line-interface
0 Answers
Your Answer