• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Kernel.system asynchronous on OSX?

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 4 Posters 571 Views 4 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.
  • B Offline
    bomastudio
    last edited by 14 Nov 2016, 21:13

    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)

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 15 Nov 2016, 19:57

      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

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

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 17 Nov 2016, 16:41

        system should be blocking. Might it be a different in the command you are invoking?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 17 Nov 2016, 21:25

          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.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement