Skip to content

exitCode -1 is error code after process closed #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

creator4ever
Copy link

Function proc_close returns -1 when error occurred, success value can be equal or great then 0

Function proc_close returns -1 when error occurred, success value can be equal or great then 0
@mikehaertl
Copy link
Owner

@creator4ever From PHP's manual on proc_close():

Returns the termination status of the process that was run. In case of an error then -1 is returned.

So it should return the termination status of the process. According to here only status 0 indicates a successful termination:

Every command returns an exit status (sometimes referred to as a return status or exit code). A successful command returns a 0, while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code. Well-behaved UNIX commands, programs, and utilities return a 0 exit code upon successful completion, though there are some exceptions.

Looking at the comments on the proc_close() manual I agree though, that things can be a bit more complicated. So maybe there's some room for improvement, but the fix you propose would introduce new problems. Not sure about a better fix.

@mikehaertl
Copy link
Owner

As an example just look at the test case for executing a non existing command. With your change, execute() would now return success in this case, because the exit code is 127:

https://github.com/mikehaertl/php-shellcommand/blob/master/tests/CommandTest.php#L141

@glensc
Copy link

glensc commented May 27, 2019

on linux (unixes) the process exit code is unsigned integer of size char (8 bits). so (signed)(char)-1 is converted as (unsigned)(char)127.

draw out the bits to visualize

@mikehaertl
Copy link
Owner

Should be fixed with #41.

@mikehaertl mikehaertl closed this Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants