php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63567 exec() always yields a 1 return code
Submitted: 2012-11-20 16:19 UTC Modified: 2012-11-28 12:02 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: seld@php.net Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 5.5.0alpha1 OS: Windows 7 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: seld@php.net
New email:
PHP Version: OS:

 

 [2012-11-20 16:19 UTC] seld@php.net
Description:
------------
Running exec() seems to detect a non-zero (and specifically 1) return code/exit code for the process. No matter what process. It also affects the proc_open class of functions so there is not even a decent workaround as far as we know.

Works on my machine but @johmue on github has the issue consistently. He tried with all latest 5.2, 5.3 and 5.4, even 5.5-alpha1. They all do the same. Yet on my machine 5.4.8 works fine. At first sight I have exactly the same OS and PHP build that he does, so this makes no sense to me. There must be something wrong in his environment but we are not able to figure out what causes it.

Note that trying the same thing in the shell directly yields a correct result, so the issue seems to be in php, for example this works:

C:\>dir
[snip]
C:\>echo %errorlevel%
0

You can find the full thread below, but I tried to sum it up above:

https://github.com/composer/composer/issues/613

Test script:
---------------
C:\>php -r "exec('dir', $out, $ret);var_dump($ret);"


Expected result:
----------------
int(0)


Actual result:
--------------
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung
ist falsch.
int(1)


----

Interstingly, it does output the wrong return code, and also prints this warning saying that the syntax of the filename/command is wrong.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-20 17:57 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-11-20 17:57 UTC] pajoye@php.net
Can't reproduce it here.

On which system or PHP version(s) does it happen exactly?
 [2012-11-21 08:05 UTC] circus2 at web dot de
It's happening on a Win 7 Home Premium 64Bits running with PHP 5.4.8 VC9 x86 
Thread Safe edition but I can reproduce it with every PHP (5.2, 5.3, 5.5alpha) 
edition.

Unfortunately I have also this weird syntax error.

I have no clue what's going on. I also played with the php-cli.ini, with my system 
path and so on.
 [2012-11-27 09:47 UTC] seld@php.net
-Status: Feedback +Status: Open
 [2012-11-27 09:51 UTC] pajoye@php.net
@circus

ini settings won't affect anything in this area using cli.

Do you always use the TS version? Can you test only in CLI please and post the 
result here?
 [2012-11-27 09:51 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-11-27 12:32 UTC] circus2 at web dot de
I already tried it in CLI mode and I tried TS as well as NTS. I also played with 
the php-cli.ini and also tried it without renaming the ini-files (fresh php 
copies). Also played with the system path to add git / php and everything 
involved.

Nothing changed. I believe it's a setting of my environment or some programm 
hooked on the cmd.exe

I still get return code 1 and the syntax error - but the command is executed. Is 
there any command i can use to cross check something.
 [2012-11-27 12:43 UTC] pajoye@php.net
@circus

please do not try with git but only what is used in this report. This is the most 
simple command and no git specific (or whatever is used behind it) are involved.

And again, under CLI the ini settings do not matter, simply run the script with 
php.exe -n test.php
 [2012-11-27 15:03 UTC] circus2 at web dot de
Ok.

I have a file called test.php:

<?php
exec('dir', $out, $ret);
var_dump($ret);

when I execute with PHP I get the following output:

C:\Test>php -n test.php
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung
ist falsch.
int(1)

when I execute it directly in the shell I get:

C:\Test>php -r "exec('dir', $out, $ret);var_dump($ret);"
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung
ist falsch.
int(1)

when I use the commands without PHP I get:

C:\Test>dir
 Datenträger in Laufwerk C: ist ACER
 Volumeseriennummer: xxxxx

 Verzeichnis von C:\Test

27.11.2012  15:54    <DIR>          .
27.11.2012  15:54    <DIR>          ..
27.11.2012  15:56                47 test.php
               1 Datei(en),             47 Bytes
               2 Verzeichnis(se), 171.682.844.672 Bytes frei

C:\Test>echo %errorlevel%
0


The commands are executed in every case. So I can add var_dump($out); to 
test.php and get:

 C:\Test>php -n test.php
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung
ist falsch.
array(10) {
  [0]=>
  string(36) " Datenträger in Laufwerk C: ist ACER"
  [1]=>
  string(30) " Volumeseriennummer: xxxxx"
  [2]=>
  string(0) ""
  [3]=>
  string(24) " Verzeichnis von C:\Test"
  [4]=>
  string(0) ""
  [5]=>
  string(37) "27.11.2012  16:01    <DIR>          ."
  [6]=>
  string(38) "27.11.2012  16:01    <DIR>          .."
  [7]=>
  string(44) "27.11.2012  16:01                63 test.php"
  [8]=>
  string(48) "               1 Datei(en),             63 Bytes"
  [9]=>
  string(60) "               2 Verzeichnis(se), 171.683.024.896 Bytes frei"
}
int(1)
 [2012-11-27 15:53 UTC] pajoye@php.net
To me it looks like a git issue. Which git version and build do you use?
 [2012-11-27 16:55 UTC] pajoye@php.net
Arg, misread.

So dir has the same issue.

Please tell me again:

- which PHP version you use (5.4.9 f.e.)
- exact windows version (check "My computer" > system)
 [2012-11-28 07:55 UTC] circus2 at web dot de
1. I use PHP 5.4.9, VC9, x86, TS from http://windows.php.net

2. Win7 SP1 Home Premium 64 Bit
 [2012-11-28 12:01 UTC] circus2 at web dot de
Problem solved! I'm so sorry about all these inconveniences and on the other 
side thank you for your support.

The problem was a small tool called Ansicon it hooks on the autoload of cmd.exe 
in the windows registry. I used it a couple of months ago but uninstalled it 
immediately. It seem to have no effect by this time but it looks now like the 
uninstall procedure doesn't care about the windows registry keys it has made 
when installed.

So I deleted these keys and now everything is fine. No syntax error and status 
code is 0. \o/

Thank you
 [2012-11-28 12:02 UTC] pajoye@php.net
Not a php issue
 [2012-11-28 12:02 UTC] pajoye@php.net
-Status: Feedback +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC