php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74074 "||" is not useful on windows's program execution function.
Submitted: 2017-02-10 11:14 UTC Modified: 2017-02-15 17:33 UTC
From: phith0n dot ph2f at gmail dot com Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 5.6.30 OS: Windows
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: phith0n dot ph2f at gmail dot com
New email:
PHP Version: OS:

 

 [2017-02-10 11:14 UTC] phith0n dot ph2f at gmail dot com
Description:
------------
I use iis7.0 && php5.6.30(I also test in apache+php, the result is same) to run following php code

```
<?php
$cmd = "error_command || whoami";
exec($cmd, $output, $return_val);
var_dump($output);
var_dump($return_val);
?>
```

If the first command is wrong, then the second command wouldn't be executed, the output is

```
array(0) { } int(1)
```

But I run the code on windows+built-in webserver, the output is

```
array(1) { [0]=> string(12) "71ec\phithon" } int(0)
```

Cli's result:

```
F:\PHPStudy\WWW>F:\soft\php-5.6.30-Win32-VC11-x86\php.exe test\a.php
'error_command' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
array(1) {
  [0]=>
  string(12) "71ec\phithon"
}
int(0)
```

So why php has 2 different results?

Test script:
---------------
<?php
$cmd = "error_command || whoami";
exec($cmd, $output, $return_val);
var_dump($output);
var_dump($return_val);
?>

Expected result:
----------------
array(1) { [0]=> string(12) "71ec\phithon" } int(0)

Actual result:
--------------
array(0) { } int(1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-15 17:33 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2017-02-15 17:33 UTC] ab@php.net
Thanks for the report. Your assumption doesn't sound correct. "A || B" is the exact construct, so then "if A fails, execute B". The fact that the concrete call to whoami doesn't give an output is rather because it's invoked from a process, possibly impersonated, started by IIS. If the exact issue is whoami, you might want to switch to get_current_user() for more compatibility. Otherwise - the difference to CLI mentioned is influenced by the environment where some command is executed.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC