Skip to content
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

Redirecting standard streams in Proc causes wrong exit code #4531

Closed
p6rt opened this issue Sep 11, 2015 · 5 comments
Closed

Redirecting standard streams in Proc causes wrong exit code #4531

p6rt opened this issue Sep 11, 2015 · 5 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Sep 11, 2015

Migrated from rt.perl.org#126037 (status was 'rejected')

Searchable as RT126037$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 11, 2015

From @ShimmerFairy

$ perl6 -e 'say ?run("false")'
False
$ perl6 -e 'say ?run("false", :out)'
True
$ perl6 -e 'say ?run("false", :err)'
True
$ perl6 -e 'say ?run("false", :in)'
True

It appears that specifying any kind of standard stream fails to set the exit code properly ("false" is either a shell built-in or a program otherwise available on linux that does nothing but give a failing exit code). It appears to be down at the VM level, so I don't know if the problem exists on both Moar and JVM. On MoarVM at least, it seems that asking for any of those streams doesn't set up a pointer to the exit-code variable in the struct used to execute a new process.

For reference, bash at least still returns the appropriate exit code​:

$ false </dev/null >/dev/null 2>/dev/null
$ echo $?
1
$ perl6 -e 'say run("false", :in, :out, :err).exitcode'
0

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 11, 2015

From @FROGGS

Thing is that you do not redirect, you capture the streams.

So if you capture out, you need to read the output and close it. The return value of close will then tell you the right exit code.
This is because when you state that you capture the stream(s), the external program was not started yet.

It will start to run when you feed it input and close in, or when you read its output and close that stream.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 11, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 11, 2015

@FROGGS - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this Sep 11, 2015
@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Sep 11, 2015

From @FROGGS

Thing is that you do not redirect, you capture the streams.

So if you capture out, you need to read the output and close it. The
return value of close will then tell you the right exit code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.