IO like object

Hi List,

i have an IO like object (in this case win32 pipes, connected to a child process). If i can provide a read and write method is there a way to get all the other IO methods for free? (like getc, each, each_byte, print, printf....)

cheers

Simon

Hi Simon

Nice job on finding a solution to unwanted command prompts with popen()
and backticks on win32.

Guessing this is on the same track, perhaps the standard 'stringio' library
could be used to supply IO-esque methods to string input and output from
Win32API calls?

alex

Simon Kröger wrote:

···

Hi List,

i have an IO like object (in this case win32 pipes, connected to a child process). If i can provide a read and write method is there a way to get all the other IO methods for free? (like getc, each, each_byte, print, printf....)

cheers

Simon

Have you considered creating a subclass from IO and defining the necessary methods?

···

On Sep 11, 2005, at 6:46 PM, Alex Fenton wrote:

Hi Simon

Nice job on finding a solution to unwanted command prompts with popen()
and backticks on win32.

Guessing this is on the same track, perhaps the standard 'stringio' library
could be used to supply IO-esque methods to string input and output from
Win32API calls?

alex

Simon Kröger wrote:

Hi List,
i have an IO like object (in this case win32 pipes, connected to a child process). If i can provide a read and write method is there a way to get all the other IO methods for free? (like getc, each, each_byte, print, printf....)
cheers
Simon

A module defining all other methods based on just would also
work. Then just include it.

I used both approaches for my Cursor classes (superset of IO
functionality but a different API). You would include one
module if your class defined just insert/delete (either
direction), another if it defined those plus read/write an
element (either direction), and another if you defined only
forward operations plus a skip back one element. The project
is here:

http://rubyforge.org/projects/cursor/

I guess I could add another module to include if you want to
make a cursor look like an IO. I didn't want that to be the
default because putting all this in Cursor would add a lot of
clutter as it already emulates much of the Array/String API.
Also the method naming in IO didn't seem appropriate for Cursor
which can handle more than just strings/characters and
symmetrically goes in both directions.

···

--- Logan Capaldo <logancapaldo@gmail.com> wrote:

On Sep 11, 2005, at 6:46 PM, Alex Fenton wrote:

> Hi Simon
>
> Nice job on finding a solution to unwanted command prompts
with
> popen()
> and backticks on win32.
>
> Guessing this is on the same track, perhaps the standard
'stringio'
> library
> could be used to supply IO-esque methods to string input
and output
> from
> Win32API calls?
>
> alex
>
> Simon Kröger wrote:
>
>> Hi List,
>> i have an IO like object (in this case win32 pipes,
connected to a
>> child process). If i can provide a read and write method
is there
>> a way to get all the other IO methods for free? (like
getc, each,
>> each_byte, print, printf....)
>> cheers
>> Simon
>>
>
>

Have you considered creating a subclass from IO and defining
the
necessary methods?

__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005

Logan Capaldo wrote:

Hi Simon

Nice job on finding a solution to unwanted command prompts with popen()
and backticks on win32.

Guessing this is on the same track, perhaps the standard 'stringio' library
could be used to supply IO-esque methods to string input and output from
Win32API calls?

alex

Simon Kröger wrote:

Hi List,
i have an IO like object (in this case win32 pipes, connected to a child process). If i can provide a read and write method is there a way to get all the other IO methods for free? (like getc, each, each_byte, print, printf....)
cheers
Simon

Have you considered creating a subclass from IO and defining the necessary methods?

'considered' is the right word. I just don't know which would be the necessary methods. In fact (but without looking at the code yet) i realy have the feeling most of them are directly mapped to the C equivalents.
If this is the case one would have to code them all from scratch.

In the meantime i figured out how to create real ruby IO objects from these pipes - but this does not work on ruby < 1.8.3 :-/
(The methods are there at least since 1.6 but they state 'no such file')

BTW (and to give credits): There is a C extension on

http://rubyforge.org/projects/win32utils/

called open3 which should be able to do the same. (but i would like a solution without having to start a compiler)

Conclusion: use 1.8.3 or the win32utils.
(if someone could figure out why IO.new doesn't like my pipes in ruby < 1.8.3 i would be happy of course)

cheers

Simon

···

On Sep 11, 2005, at 6:46 PM, Alex Fenton wrote: