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

    Starting a process in background using Ruby system()

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 1.6k Views 5 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.
    • Al HartA Offline
      Al Hart
      last edited by

      I couldn't find anything else about this in the Forum, so I thought I would pass it along.

      In previous versions of SketchUp, we used Win32API to start processes.

      We changed all these to use the Ruby system() command for SU 2014.

      Sometime we want to start a process where ruby does not wait for it to complete.

      You can do this with the DOS start command:

      system('start ' + scommand_line)

      The the program in the command line will execute and ruby will continue without waiting for it. (Note the command line contains the name of the .exe and also some command arguments)

      However, due to quirk with "start", this fails if the command line starts with double quotes. I found this comment on the web:

      "START has a peculiarity involving double quotes around the first parameter. If the first parameter has double quotes it uses that as the optional TITLE for the new window. "

      So, just adding a blank set of double quotes fixed our problem. This works whether the command line actually starts with a double quote or not

      system('start "" ' + scommand_line)

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        Wow, that's one of them thing that could have you stuck for hours. Thanks for sharing!

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

          ... but it is PC only correct ?

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            How do you handle folder name with spaces?

            cmd = "c:\program files\..."

            system('start "" ' + cmd)

            produces an error message which says that Windows cannot find 'c:\program'

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

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

              given:
              cmd = "c:\\program files\\..."

              one of::
              system( "start \"#{cmd}\"" )

              or:
              system( %[start "#{cmd}"] )

              or:
              system( "start", %["#{cmd}"] )

              or:
              %x[start "#{cmd}"]


              See Ruby docs on literal strings:
              http://ruby-doc.org/core-2.0.0/doc/syntax/literals_rdoc.html#label-Strings

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @dan rathbun said:

                given:
                cmd = "c:\\program files\\..."

                one of::
                system( "start \"#{cmd}\"" )

                or:
                system( %[start "#{cmd}"] )

                or:
                system( "start", %["#{cmd}"] )

                or:
                %x[start "#{cmd}"]


                See Ruby docs on literal strings:
                http://ruby-doc.org/core-2.0.0/doc/syntax/literals_rdoc.html#label-Strings

                Thanks Dan. Each of these options do not fail but they do not succeed either. What I was trying to do is create a plugin that would allow me to pick a plugin from a list and create a .rbz file from it using the command line version of 7Zip. This is the final solution

                zip = "c;/program files/7-zip/7z"; 
                rbz = "c;/users/public/sketchup/plugins/dummy tool.rbz"; 
                rb = "c;/users/public/sketchup/plugins/dummy tool.rb"
                cmd = "\"#{zip}\" a -tzip \"#{rbz}\" \"#{rb}\""; puts cmd
                #system( "start  \"#{cmd}\"" )
                #system( %[start "#{cmd}"] )
                #system( "start", %["#{cmd}"] )
                #system( %x[start "#{cmd}"] )
                system('start "" ' + cmd)
                
                
                

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  some zip program require the .zip extension, so you could try using rename...

                  I'm on a mac, but maybe something like...

                  zip = "c;/program files/7-zip/7z"
                  zipped = "c;/users/public/sketchup/plugins/dummy tool.zip" 
                  rbz = "c;/users/public/sketchup/plugins/dummy tool.rbz"
                  rb = "c;/users/public/sketchup/plugins/dummy tool.rb"
                  cmd = "\"#{zip}\" a -tzip \"#{zipped}\" \"#{rb}\""; puts cmd
                  %x('start "" ' + cmd)
                  File.rename(zipped, rbz)
                  
                  

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • sdmitchS Offline
                    sdmitch
                    last edited by

                    @driven said:

                    some zip program require the .zip extension

                    john

                    Not a problem with 7-Zip.

                    The -tzip sets the output format.

                    Nothing is worthless, it can always be used as a bad example.

                    http://sdmitch.blogspot.com/

                    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