IO.popen

I assume the doc’s are “just wrong” when they say you can access an
IO.popen with any mode you’d like?

http://ruby-doc.org/core/classes/IO.html#M002242

IO.popen(“gocr”, “rw”)
ArgumentError: invalid access mode rw

Is this expected?
-r

Roger P. wrote:

I assume the doc’s are “just wrong” when they say you can access an
IO.popen with any mode you’d like?

http://ruby-doc.org/core/classes/IO.html#M002242

IO.popen(“gocr”, “rw”)
ArgumentError: invalid access mode rw

Is this expected?

Yes. It doesn’t say “any mode you’d like”; it says “any of the modes
listed in the description for class IO” - that is, any valid mode :slight_smile:

You’re probably looking for mode “r+” or “a+”

http://ruby-doc.org/core/classes/IO.html

Hello Roger,

http://ruby-doc.org/core/classes/IO.html#M002242

IO.popen(“gocr”, “rw”)
ArgumentError: invalid access mode rw

When I want to read and write from the IO.popen’ed command, I use

IO.popen(cmd, “r+”)

but I do not remember from which source I found I had to use “r+”
rather than the more expected “rw”

Cheers,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs