Doc #78699 [Opn->Ver]: shell_exec on windows runs in text mode, this should be noted in the docs.

From: Date: Sun, 20 Oct 2019 08:05:49 +0000
Subject: Doc #78699 [Opn->Ver]: shell_exec on windows runs in text mode, this should be noted in the docs.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17026@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78699&edit=1 ID: 78699 Updated by: cmb@php.net Reported by: phpstuff at cresstone dot com Summary: shell_exec on windows runs in text mode, this should be noted in the docs. -Status: Open +Status: Verified Type: Documentation Problem -Package: Documentation problem +Package: Program Execution Operating System: Windows PHP Version: 7.3.10 Block user comment: N Private report: N New Comment: Indeed, you're right. I think treating this as documentation issue is the right way. Thanks for reporting! Previous Comments: ------------------------------------------------------------------------ [2019-10-20 07:39:44] phpstuff at cresstone dot com Disregard that last edit, stream_get_contents works fine and I've been at the keyboard too long. ------------------------------------------------------------------------ [2019-10-20 07:30:35] phpstuff at cresstone dot com 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... ------------------------------------------------------------------------ [2019-10-20 05:35:07] 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... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78699&edit=1

« previous php.doc.bugs (#17026) next »