Doc #78699 [Opn]: shell_exec on windows runs in text mode, this should be noted in the docs.
| From: | phpstuff at cresstone dot com | Date: | Sun, 20 Oct 2019 07:30:35 +0000 |
| Subject: | Doc #78699 [Opn]: 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-17024@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
User updated by: phpstuff at cresstone dot com
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
Type: Documentation Problem
Package: Documentation problem
Operating System: Windows
PHP Version: 7.3.10
Block user comment: N
Private report: N
New Comment:
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...
Previous Comments:
------------------------------------------------------------------------
[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