neemzy
neemzy

Reputation: 1929

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:

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)

Upvotes: 0

Views: 283

Answers (1)

neemzy
neemzy

Reputation: 1929

OK, my apologies, I'm stupid. I had the answer right in front of me the whole time.

I re-read more carefully the issue on Composer's GitHub I linked to (https://github.com/composer/composer/issues/1373). In it, the person encountering the issue says he fixed it by removing the call to cls in a .bat file he got executed at shell start by calling it in Windows's registry (HKCU\Software\Microsoft\Command Processor\AutoRun).

I actually had a .bat file called here on an unrelated matter, which contained a call to cls. So my Windows and PHP are fine - I just set up somthing aside that caused the trouble, which I did not realize until now.

Still good to know that this type of stuff can mess with PHP accessing the shell... Thank you anyway @hakre for your time.

Upvotes: 1

Related Questions