• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Capturing $sterr output

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 4 Posters 377 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    danielbowring
    last edited by 27 Apr 2012, 06:03

    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() 
    
    
    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 27 Apr 2012, 18:48

      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 the puts() method.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 27 Apr 2012, 22:40

        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
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 27 Apr 2012, 23:45

          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
          
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 27 Apr 2012, 23:48

            @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'm looking for an example where custom Console(s) will not interfere with the "native" Sketchup console.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • F Offline
              fredo6
              last edited by 28 Apr 2012, 07:53

              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

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 28 Apr 2012, 08:46

                @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?

                Hi

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by 28 Apr 2012, 09:23

                  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?

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    fredo6
                    last edited by 28 Apr 2012, 12:16

                    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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      danielbowring
                      last edited by 4 May 2012, 00:19

                      @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 😄

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        1/10
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement