Run Terminal Scripts from Swift in your Mac app — honza dvorsky http://honzadvorsky.com/blog/2015/5/14/run-terminal-scripts-from-swift-in-a-mac-app …
@mjtsai Good point. How could I do that? The buffer limit is 65536 bytes (OS X pipe buffer size), not sure what happens if overflown :)
-
-
@czechboy0 Build up the output/error data a chunk at a time. Don't -waitUntilExit. Keep running the run loop until file handles are empty. -
@mjtsai But what if the script isn't outputting anything for a while? Wouldn't that terminate before the script itself does? -
@czechboy0 No, because instead of calling -waitUntilExit you run your own loop until the output and error are finished. -
@mjtsai And those are guaranteed to only finish when the whole script has terminated? - View other replies
-
@czechboy0 But note that you can get NSTaskDidTerminateNotification before the last NSFileHandleReadCompletionNotification… -
@mjtsai Hmm. Sorry, I still can't see exactly how to quickly improve the script I have. Maybe fork the gist and show me? :) -
@czechboy0 No time for that at the moment, but maybe I can write a blog post sometime. -
@mjtsai Let me know if you do. Thanks!
-
-
@czechboy0 As I recall, -waitUntilExit will just hang. Solution is to register both file handles for read completion notifications.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
honza dvorsky
Michael Tsai