Pause until action is complete
-
@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)
-
Ah ok, sorry for posting it in the wrong section
-
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!
-
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?
-
some text files will available for input is one thing that will be available after the system call
-
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.
-
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.pidthe 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.)
-
That's great! Thanks Dan and Chris
-
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.
-
@zane said:
That's great! Thanks Dan and Chris
No problem, I fixed a mistake in the done=() method of the second example (above.)
Advertisement