Monday, 9 September 2013

Extra character in PHP's exec() output on Windows 7 CLI

Extra character in PHP's exec() output on Windows 7 CLI

Without any apparent reason, I can't update my Composer-managed
dependencies anymore. After some investigation, it turns out that PHP
prepends an extra character to any use of its exec method.
Basic example :
php -r "var_dump(exec('echo lol', $output, $exit), $output, $exit);"
Gives out :
string(4) "Šlol"
array(1) {
[0] =>
string(4) "Šlol"
}
int(0)
That Š character actually is an FF (formfeed) character (0x0C).
My Googling took me here:
Composer won't update dependencies due to random formfeed char (0x0c) -
Composer Issue #1374
But it appears that my problem differs from the one in this topic, as in
it, the dreaded character appears with shell_exec and not exec. In my case
it does appear with exec.
Any thoughts about this ? I wondered whether I should post here or at
SuperUser, feel free to move this question if it doesn't belong here.
EDIT : BTW, I'm on Windows 7 64 bits, using Wamp with PHP 5.4.12 :)
EDIT 2 : Output for php-v :
PHP 5.4.12 (cli) (built: Feb 25 2013 00:29:22)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Output for php --ini :
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: C:\wamp\bin\php\php5.4.12\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)

No comments:

Post a Comment