sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    MSDOS in Ruby Console

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 6 Posters 1.1k Views 6 Watching
    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.
    • J Offline
      Jim
      last edited by

      @martinrinehart said:

      Jim, can I get this done in your WebConsole?

      Sure, this is how I would do it:

      158.jpg

      😆

      Seriously, WebConsole either evals the contents of the textarea, or saves it to disk and loads the contents - I don't remember.

      Hi

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @martinrinehart said:

        Any way to lose the quotes, short of writing a shell?

        **** Warning! ****
        Kernel.exec('cmd.exe')
        will cause Sketchup to 'hang' on Win32.
        When the shell is exited, BugSplat! closes Sketchup.
        (This is because Kernel.exec replaces the current Process, which is the interpreter process started by Sketchup.)

        So to use a DOS shell, instead use 1 of two choices:

        DOS shell in a Sub Process
        Kernel.system('cmd.exe')
        which runs in a subprocess, and also returns a boolean value of success( TrueClass) or failure( FalseClass).
        As a bonus, it can set a detailed error code in the Ruby global $?.
        And ugly side-effect however, is that Sketchup stops and waits while the shell is open. The Windows TaskManager reports that sketchup.exe is 'not responding', which is true; but will return to normal operation once the DOS shell is closed.
        If the user types 'exit' in the shell, Kernel.system returns true with exitcode 0; if the user clicks the shell window close button then Kernel.system returns false with exitcode 58.

        DOS shell in a Separate Process
        UI.openURL('cmd.exe')
        Simple and works because of the $SAFE level is set to 0 by default.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @martinrinehart said:

          I've hacked up a little bit of DOS that let's you change, make, remove and list contents of directories and delete files in the Ruby Console.
          What's wrong with the standard included classes File and Dir ??
          You can do all that would be desired with their methods.

          @martinrinehart said:

          It's useful as is, but I'm not happy that you have to put all the params in quotes: ...
          Any way to lose the quotes, short of writing a shell?
          In many cases, since we migrated to 32bit Windows, we've had to put quotes around most pathnames or filenames that have spaces in DOS command scripts anyway... so it's not a big deal.
          _

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            Martin, Dan, That's very nifty stuff. Thanks.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              Stumbled on this. Didn't know it would happen, but it of course makes sense, because of the way MS Windows works.

              If you wish to open a File Explorer window, to some given folder, use UI.openURL method.

              
              # use empty quote quirk to get SU folderpath
              supath = Sketchup.find_support_file("")
              # open a File Explorer
              UI.openURL(supath)
              
              

              _

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                @dan rathbun said:

                Stumbled on this. Didn't know it would happen, but it of course makes sense, because of the way MS Windows works.

                If you wish to open a File Explorer window, to some given folder, use UI.openURL method.

                
                > # use empty quote quirk to get SU folderpath
                > supath = Sketchup.find_support_file("")
                > # open a File Explorer
                > UI.openURL(supath)
                > 
                

                _

                UI.openURL will open/execute any filepath passed to it - if that's a folder it opens it in Windows-Explorer, if it's a file it opens with its default application, if it's an application/batch-file it runs, if it's a URL it opens in a web-browser [default app].

                TIG

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @tig said:

                  UI.openURL will open/execute any filepath passed to it - if that's a folder it opens it in Windows-Explorer, if it's a file it opens with its default application, if it's an application/batch-file it runs, if it's a URL it opens in a web-browser [default app].

                  I just tested safe levels with UI.openURL and the setting of $SAFE has no effect on the function of executables started by UI.openURL.

                  Could this be a security issue?

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    FYI: MSDOS Shell Default Font

                    It's a pain in the butt to get the Font set in the DOS shell.

                    Try changing the 'DefaultFont' registry setting in:
                    'HKEY_CURRENT_USER\Software\Microsoft\Command Processor'

                    You may need to Log off and back on, before the setting takes effect.

                    There is also a list of fonts at:
                    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont' where the list numbers should begin at 0.
                    But I haven't had any luck getting the list to appear in the Console Properties dialog.

                    (EDIT)By the way, the settings for the Console Properties dialog are saved at:
                    'HKEY_CURRENT_USER\Console'

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      MartinRinehart
                      last edited by

                      @dan rathbun said:

                      What's wrong with the standard included classes File and Dir ??
                      You can do all that would be desired with their methods.

                      That's all I've done:
                      def cd( path ) Dir::chdir( path ) end

                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @martinrinehart said:

                        @dan rathbun said:

                        What's wrong with the standard included classes File and Dir ??
                        You can do all that would be desired with their methods.

                        That's all I've done:
                        def cd( path ) Dir::chdir( path ) end

                        Shell Commands are already allowed within Ruby. [Examples for PC win32 platform, but also applies to Mac OSX.]

                        use the %x delimiter, as in: %x{dir *.skp}
                        or backquoted strings, as in: dir *.skp

                        (from: Programming Ruby -
                        The Pragmatic Programmer's Guide
                        )

                        The Ruby Language > Expressions > Single Terms
                        Shell Command. A shell command is a string enclosed in backquotes, or in a general delimited string (page 200) starting with %x. The value of the string is the standard output of running the command represented by the string under the host operating system's standard shell. The execution also sets the $? variable with the command's exit status.
                        [Example - '.c' changed to '.skp';'ls' changed to 'dir'.]
                        %(#BF0000)[filter = "*.skp"
                        files = dir #{filter}
                        files = %x{dir #{filter}}]

                        ! Backquoted strings allow replacement like doublequoted strings !

                        Expressions > Miscellaneous Expressions**http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html**
                        Command Expansion
                        If you enclose a string in backquotes, or use the delimited form prefixed by %x, it will (by default) be executed as a command by your underlying operating system. The value of the expression is the standard output of that command.

                        ! The output is a String, so any String method can be applied to the expression: Ex:
                        dir.include?('.jpg')
                        returns true if there are any jpeg files in the dir
                        _

                        I'm not here much anymore.

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

                        Advertisement