• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Pause until action is complete

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

    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
    • M Offline
      mitcorb
      last edited by 3 Apr 2011, 02:02

      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
      • G Offline
        Gaieus
        last edited by 3 Apr 2011, 07:39

        @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 3 Apr 2011, 09:48

          Ah ok, sorry for posting it in the wrong section

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gaieus
            last edited by 3 Apr 2011, 10:12

            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
            • C Offline
              Chris Fullmer
              last edited by 3 Apr 2011, 18:51

              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 7 Apr 2011, 17:13

                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
                • C Offline
                  Chris Fullmer
                  last edited by 7 Apr 2011, 18:59

                  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
                  • D Offline
                    Dan Rathbun
                    last edited by 7 Apr 2011, 22:16

                    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 7 Apr 2011, 23:15

                      That's great! Thanks Dan and Chris πŸ˜„

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Dan Rathbun
                        last edited by 8 Apr 2011, 01:32

                        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
                        • D Offline
                          Dan Rathbun
                          last edited by 8 Apr 2011, 01:34

                          @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
                          1 / 1
                          • First post
                            1/12
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement