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

IO.pipe #1097

Closed
route opened this issue Oct 8, 2013 · 5 comments
Closed

IO.pipe #1097

route opened this issue Oct 8, 2013 · 5 comments

Comments

@route
Copy link

route commented Oct 8, 2013

This code works properly on MRI

def test_closing_write_end_of_pipe
  r, w = IO.pipe

  stdout = STDOUT.dup
  stdout.autoclose = false
  $stdout = w
  STDOUT.reopen(w)

  pid = Process.spawn('sleep 3 && echo "cat"')
  w.close

  STDOUT.reopen(stdout)
  $stdout = STDOUT

  r.read
end

At the end we will see the output of subprocess. We don't need write end of pipe in our process so we can freely close it. But for jruby the output is an empty string.

@headius
Copy link
Member

headius commented Oct 10, 2013

Because JRuby may share a process with other applications, our reopen is simulated; we do not actually modify stdout (or stderr, or any open IO stream) when you reopen it. The target object just swaps "descriptors" with the given object. I'm not sure this is something we can make work without large changes and damaging all other users of stdio on the same JVM.

@route
Copy link
Author

route commented Oct 10, 2013

Thank you @headius, is there any workaround? If I don't close it at the beginning I'll get IOError stream closed at the end.

@rtyler
Copy link

rtyler commented Jan 30, 2015

I'm wondering if this issue should be closed or not

@headius
Copy link
Member

headius commented Jan 30, 2015

This does work in 9k on platforms where it's supported (not Windows). It will never work like MRI in the 1.7.x line. So we'll call it fixed in 9k.pre1.

@headius headius closed this as completed Jan 30, 2015
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Jan 30, 2015
@route
Copy link
Author

route commented Feb 6, 2015

Thank you guys! I should definitely check out 9k!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants