Skip to content

proc_open() fails for non-existent commands with error: posix_spawn() failed #12589

Closed
@ausi

Description

@ausi

Description

Since #7933 there is a change in how proc_open() handles non-existent commands.

The following code:

<?php
var_dump($p = proc_open(["invalid_command"], [], $pipes)); 
var_dump(proc_close($p));

Resulted in this output:

PHP Warning:  proc_open(): posix_spawn() failed: No such file or directory in Command line code on line 1
bool(false)
PHP Fatal error:  Uncaught TypeError: proc_close(): Argument #1 ($process) must be of type resource, false given in Command line code:1

But I expected this output instead (as it was before PHP 8.3):

resource(4) of type (process)
PHP Warning:  proc_open(): Exec failed: No such file or directory in Command line code on line 1
int(127)

The different behavior only occurs when passing the command as an array, passing it as a string still behaves as it always did:

<?php
var_dump($p = proc_open("invalid_command", [], $pipes)); 
var_dump(proc_close($p));

Results in this output for all PHP Versions:

resource(4) of type (process)
sh: invalid_command: command not found
int(127)

As calling non-existent commands is probably pretty common, I think the old behavior of returning exit code 127 should be restored for that case.

PHP Version

PHP 8.3.0RC5

Operating System

macOS 13.6 (22G120)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions