Kernel.system asynchronous on OSX?
-
I want to run an external software (that create a txt file to be post-processed by me) with system() call.
On Windows all fine. The system(cmd1,...) works, creates the txt file and then my ruby-code processes it as I want.
On OsX, on the other hand, it seems to work asynchronous: the system(cmd1,...) works and creates the txt BUT my ruby-code try to process the txt file IMMEDIATELY after the system call without waiting for its existence. I have to re-lauch my script, and then it finds the *.txt file and works ok....
Do you have some experience of it?
SketchUp 2014,2015,2016,2017 + Windows7 (all ok)
SketchUp 2015 + OsX 10.8 (bad) -
it's very hard to ascertain your code's logic from your description...
can you post a 'working/failing' example...
system calls work great on osx, but I normally use backticks `` or %x variants...
john
-
system should be blocking. Might it be a different in the command you are invoking?
-
I usually use a timer in this scenario, to check when the file exists, then cancel the timer and call the post processing method.
@tid = UI;;start_timer(0.5,true) { if File.exist?(@filepath) UI;;stop_timer(@tid) post_process(@filepath) end }EDIT(Add): Also, I would usually have a counter variable that gets incremented each timer loop, and a max number of trys, if the file never becomes "ready" then I also exit the timer and somehow display a warning or message that things did not work.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement