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?

class IO - RDoc Documentation

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,

class IO - RDoc Documentation

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,