[Note: parts of this message were removed to make it a legal post.]
This will be difficult to do because then StringIO would somehow have
Well, reopen also can take a string, I believe. So it already takes
The string is interpreted as a file name. With changing type I meant that
a StringIO after #reopen (either with number, IO object or string as file
name) must behave like an IO or File object which is a different type. I
was not talking about the argument types to method #reopen but the type of
the object itself.
Yes - but what I meant was, reopen already checks its argument and
behaves differently based on what is passed in, so it *could* of course
check for a StringIO as well.
[snip]
Yes, this obviously works, but it is irrelevant to what I am trying
to do.
How would I, for example, capture all that went to standard error
You can try to do
$stderr = StringIO.new
but this works only within the same process, i.e. not for sub processes.
There is no way I am aware of to redirect a file descriptor to an in memory
structure. If you want the redirection to work for a child process and get
the data in the parent you need to use one of the popen family of methods.
I am not interested in subprocesses actually.
The problem with what you do here is that it changes the variable $stderr
to a different object (leaving the original object of course unaffected).
So it depends, I think, on code referencing $stderr rather than STDERR. (The
code whose stderr I am catching is not necessarily my own.)
Maybe I could also do const_set(STDERR, my_io) before any requires. That is
something I have not tried.
Another ugly trick, of course, would be something like doing a popen, a
reopen,
then read from the pipe periodically. Or perhaps even redirect stderr to a
file
and do a File::Tail on that...
Ah, well. It is not something that will come up often.
Hal