|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-10-20 05:35 UTC] phpstuff at cresstone dot com
Description: ------------ --- From manual page: https://php.net/function.shell-exec --- On windows, shell_exe() & the backtick operator operate in text mode. When I was trying to get binary stdout from a command I encountered incorrect output, and the command I was running gave ‘broken pipe’ messages on its stderr. Any binary output that includes newlines seem to cause errors. The documentation doesn’t mention this, and took me a while to puzzle out what was happening. The work-around is to use popen() with the binary flag: $handle = popen('someCommand.exe', 'rb'); $binarySTDOUT = stream_get_contents($handle); pclose($handle); I wasn’t sure whether to file this as a language bug or just add a comment on the documentation, this report seemed like a good compromise... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 06:00:01 2025 UTC |
Edit: The correct workaround code should be: $handle = popen('someCommand.exe', 'rb'); $binarySTDOUT=""; while (!feof($handle)) $binarySTDOUT.= fread($handle, 65536); pclose($handle); stream_get_contents() does not always produce the correct data for me. I'll investigate if that's a separate issue...