Capturing $sterr output
-
Hey, wondering if Sketchup does anything special with $stderr?
I need to redirect $stdout and $stderr to another stream, and it works fine for $stdout but for whatever reason what you would imagine is going to $stderr is going to the ruby console regardless of the value of $stderr.
For example, if I overwrite $stderr, errors thrown in scripts will not be written to it, but instead will still appear in the ruby console.
Thoughts?
btw, here's a sample of what I'm using:
class Sample def write(str) puts "stderr got " + str end end # don't worry, in the actual code I maintain the original Sketchup;;Console instance. $stderr = Sample.new()
-
That a weird example...
... your custom class is not a subclass of
IO
... and you redirect (or attempt to,) send
$stderr
output to$stdout
, via theputs()
method. -
Think you need to re-define Sketchup::Console.write(). There are some examples in this forum. I do this to send all messages to Microsoft DebugView debugger via WIN32 OutputDebug windows system call.
Here's a cut&paste from one of my files. Actually, I don't re-define the write() method, but sub-class Sketchup::Console then point $stdout and $stderr to my class:
require 'Win32API' class JFConsole < Sketchup;;Console OutputDebugString = Win32API.new("kernel32.dll", "OutputDebugString", ['P'], 'V') alias _write_ write def write(smess="") smess = smess.to_s + "\0" OutputDebugString.call(smess) #_write_(smess) end end # redefine standard output to our new class $old_stdout = $stdout # in case you want to turn off traces $stdout = JFConsole.new $stderr = $stdout puts "-" * 40 puts Time.now puts "Starting SketchUp Debug Output" puts "$DEBUG; #{ $DEBUG }" puts "$VERBOSE; #{ $VERBOSE }" puts "-" * 40
-
I would prefer all custom classes to be author namespace wrapped:
require 'Win32API' module JF class Console < Sketchup;;Console OutputDebugString = Win32API.new("kernel32.dll", "OutputDebugString", ['P'], 'V') alias _write_ write def write(smess="") smess = smess.to_s + "\0" OutputDebugString.call(smess) #_write_(smess) end end end # module JF # use it; $stdout = JF;;Console.new
-
@Jim: Wondering.. since your custom class is a subclass of
Sketchup::Console
, do you need to alias the method, or simply callsuper
within the override ??I'm looking for an example where custom Console(s) will not interfere with the "native" Sketchup console.
-
In pas trials, I noticed that the SU error message (whether for syntax at load time or at run-time) are not handled by the console Ruby object, but send directly to the console at C level.
Fredo
-
@dan rathbun said:
@Jim: Wondering.. since your custom class is a subclass of Sketchup::Console, do you need to alias the method, or simply call super within the override ??
I think you are correct - no need to alias the write method snce I'm not re-defining it. Calling super is a better option in this case.
@unknownuser said:
In pas trials, I noticed that the SU error message (whether for syntax at load time or at run-time) are not handled by the console Ruby object, but send directly to the console at C level.
Yes, I believe you are right - but is there any way to capture these messages?
-
I can't get this to work now. I know it used to work, and had used it daily. Maybe the latest version of SketchUp changed somehow?
-
It would nice if we could redirect all messages toward a known output stream.
We can then make our own Ruby console, portable on Windows and Mac, with more goodies, like clear, split, etc....
The fact that we can't capture the errors is really ennoying, as this is one of the most crucial reason to have a console.Maybe we should ask the SU team
Fredo
-
@unknownuser said:
In pas trials, I noticed that the SU error message (whether for syntax at load time or at run-time) are not handled by the console Ruby object, but send directly to the console at C level.
@jim said:
I can't get this to work now. I know it used to work, and had used it daily. Maybe the latest version of SketchUp changed somehow?
@unknownuser said:
It would nice if we could redirect all messages toward a known output stream.
...
Maybe we should ask the SU team
I'd assume then that we are unable to capture it, as irritating as that is.Thanks all
Advertisement