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

    Pause until action is complete

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 5 Posters 719 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.
    • Z Offline
      Zane
      last edited by

      Hey guys,
      Quick question for you all. I'm doing a system call for an exe file to be run in a ruby code and I don't want the ruby code to continue until the exe has finished running, is there any code or function I can use that will pause the script till the system call is complete?
      Thanks for your time and help!

      1 Reply Last reply Reply Quote 0
      • mitcorbM Offline
        mitcorb
        last edited by

        Hi, Zane:
        As a helpful suggestion, even though you may have recently joined, this question may be better posted in the Developer's Forum, due to the advanced nature of the question.

        I take the slow, deliberate approach in my aimless wandering.

        1 Reply Last reply Reply Quote 0
        • GaieusG Offline
          Gaieus
          last edited by

          @mitcorb said:

          this question may be better posted in the Developer's Forum

          Indeed so I have moved it (like anything that I cannot understand)
          😄

          Gai...

          1 Reply Last reply Reply Quote 0
          • Z Offline
            Zane
            last edited by

            Ah ok, sorry for posting it in the wrong section

            1 Reply Last reply Reply Quote 0
            • GaieusG Offline
              Gaieus
              last edited by

              Absolutely no problem. This is the very first post in the newbie forum:

              Subject: Welcome new SketchUp user!

              @unknownuser said:

              Hello there,

              Welcome to this little SketchUp Community we have set up here!

              Welcome to this forum for all your beginners questions. You may also have more advanced questions and may post them in the appropriate forum.
              If you're not sure if your question is beginner or advanced, then don't worry too much. The world is full of worrisome people already and we want you to get that cozy - de-worried feeling here. So in that case just post it here anyway.


              Well, the original was posted some 5 years now and "this little SketchUp Community we have set up here" has grown to be the biggest ever with 70K+ members now!
              😉

              Gai...

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Hi Zane, do you have some way of knowing when the system call is done? Is there something that you can track that lets you know it is finished?

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • Z Offline
                  Zane
                  last edited by

                  some text files will available for input is one thing that will be available after the system call

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    You could have your ruby search for those files every second or something (or less if it will be faster, or more if it generally is longer). Then once it finds the files, your plugin could continue. That could be an option.

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

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

                      If your using system()
                      then the Ruby global $? returns the exit status.

                      If you have not yet used any subprocess during the current session, then $? will point at nil.

                      If you have then you can make a reference to the last Process::Status object referenced by $?, and do a comparison.

                      ` last = $?
                      system('somefile.exe')
                      if (last==nil && $? != nil) || $?.pid != last.pid

                      the system call finished

                      end`

                      I tried to get Kernel.trace_var to signal when $? changes, but it does not seem to work. ($? is a special read-only variable.)

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Z Offline
                        Zane
                        last edited by

                        That's great! Thanks Dan and Chris 😄

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

                          OK got trace_var workaround. Since system() returns true||false, we can assign the return value to a global var, and set up a trace exec string (or block if you wish,) on that global.

                          This example uses $done, but you will want to use a unique name for your global.

                          $done = nil
                          trace_var(;$done) {|var|
                            "puts('Subprocess #{$?.pid} finished with exit code #{$?.exitstatus}')"
                            # do other post system call code
                            untrace_var(;$done)
                            $done = nil
                          }
                          $done = system('somefile.exe')
                          

                          You could even use a instance var instead of a global and a attribute setter method instead of the trace_var method:

                          module Zane
                            class << self
                            @done = nil
                          
                            def done=(arg)
                              puts("Subprocess #{$?.pid} finished with exit code #{$?.exitstatus}")
                              if arg
                                # system() returned true
                                # do other post system call code
                              else
                                # system() returned false
                                # do some recovery code
                              end
                              @done = nil
                            end # def
                          
                            end # class block
                          
                            done= system('somefile.exe')
                          
                          end # module Zane
                          

                          EDIT: well I guess the instance var is not really needed unless you wish to store the return value for some reason.

                          I'm not here much anymore.

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

                            @zane said:

                            That's great! Thanks Dan and Chris 😄

                            No problem, I fixed a mistake in the done=() method of the second example (above.)

                            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