php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72902 shell_exec() is not utilizing UTF-8
Submitted: 2016-08-19 22:35 UTC Modified: 2016-08-20 10:46 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugzilla77 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.0beta3 OS: Win10 x64 Polish
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugzilla77 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-08-19 22:35 UTC] bugzilla77 at gmail dot com
Description:
------------
https://github.com/php/php-src/blob/php-7.1.0beta3/UPGRADING

"The recommended way to handle file paths, I/O and other related topics is by utilizing UTF-8."

Expected result:
----------------
shell_exec() returns UTF-8 data

Actual result:
--------------
shell_exec()does not work even in the local system code page. It returns ? instead local letters.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-19 23:57 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2016-08-19 23:57 UTC] ab@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2016-08-20 05:01 UTC] bugzilla77 at gmail dot com
-Status: Feedback +Status: Open
 [2016-08-20 05:01 UTC] bugzilla77 at gmail dot com
Testcase
--------

http://bugs.idsl.pl/php/shell_exec.7z


Actual result
-------------

C:\htdocs\wwwroot\a>chcp 1250 
Active code page: 1250

C:\htdocs\wwwroot\a>echo ���� 
����

C:\htdocs\wwwroot\a>chcp 65001 
Active code page: 65001

C:\htdocs\wwwroot\a>echo żółć 
żółć


Expected result
---------------

C:\htdocs\wwwroot\a>chcp 1250 
Active code page: 1250

C:\htdocs\wwwroot\a>echo żółć 
żółć

C:\htdocs\wwwroot\a>chcp 65001 
Active code page: 65001

C:\htdocs\wwwroot\a>echo żółć 
żółć


...because PHP 7.1 introduces "Windows Support" https://github.com/php/php-src/blob/php-7.1.0beta3/UPGRADING
 [2016-08-20 10:46 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2016-08-20 10:46 UTC] ab@php.net
Thanks for the further info. This is not specific to 7.1 changes or shell_exec, however. The content-type header imply, that all of the output is in the given charset.

Specific to 7.1 on Windows is, that the default_charset affects how the filenames are handled, but not the output from an external program. Internally, PHP will convert the given filename to/from UTF-16 using the specified default_charset. If default_charset=UTF-8, any possible filenames can be handled. Otherwise, fe default_charset=cp1250 like in this case, some filenames like Asian or Cyrillic, are likely not to be supported correctly. That will OFC also affect, how the filenames are read to PHP, and how they're output (fe in error messages, etc.). PHP already sends the corresponding headers for server SAPIs, and with 7.1 it also switches to the corresponding codepage on CLI. For instance, notice the length returned:

php.exe -r "$f = 'żółć'; touch($f); var_dump(pathinfo($f)); unlink($f);"
array(3) {
  ["dirname"]=>
  string(1) "."
  ["basename"]=>
  string(8) "żółć"
  ["filename"]=>
  string(8) "żółć"
}

php.exe -d default_charset=cp1250 -r "$f = 'żółć'; touch($f); var_dump(pathinfo($f)); unlink($f);"
array(3) {
  ["dirname"]=>
  string(1) "."
  ["basename"]=>
  string(4) "żółć"
  ["filename"]=>
  string(4) "żółć"
}

The encoding information is vital for Windows, to do the correct conversion of the filename. But, and it is even not Windows specific, not even 7.1 specific, PHP won't convert an output from some program to the default_charset. The recommendation in the UPGRADING tells exactly that - from 7.1 on the script needs to use a homogeneous encoding across all its parts, specifically filenames. Before 7.1, only Window APIs with ANSI codepage support are used, despite default_charset=utf-8.

Thanks.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 21:00:02 2026 UTC