NSTask isCompleted Handler

Hi,

Does anyone have experience with NSTask?
I’ve made a class that I use for launching async NSTask shells. (I’m using MacOSLlib because I can’t figure out how to make the declares myself.)
It works ok but after a while, I get posix_spawn error 35 (couldn’t spawn) and the whole thing crashes. The crash occurs at the NSTask.lanch command in MacOSLlib.

The problem is, sometimes it runs for an hour, sometimes it crashes within seconds. Sometimes when it’s busy (100’s per second), sometimes when it’s not busy at all.

Not sure but I think it has to do with me polling ‘.isRunning’ using a timer (within the instance) and then reading the output using NSData = Me.StdoutPipe.ReadHandle.ReadAll. Maybe some timing conflict?

Instead of using a timer, is there a trick where I somehow can add a handler to a NSTask event?
The reference doesn’t give me much to attach it to. Also, it mentions that .isRunning is no longer supported. (not sure why because it normally works on my Yosemite 10.10.4)

terminationHandler property takes a Obj-C Block

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/index.html#//apple_ref/occ/instp/NSTask/terminationHandler

As to why it’s crashing I don’t know, I’m using NSTask in my apps, but have never noticed a crash because of it.

I could add it to my plugin easily. (and route it to main thread if needed)

And works. If anyone needs that, please email me, so I can mail you a new plugin.

What is the difference to a 08/15 shell?

What’s a 08/15 shell?

08/15 is german for a standard item. nothing special.

NSTask is OS X Cocoa way for a shell and it may have some extra options.

Ok. lol
Well, a 08/15 is not allowed if you want your App sandboxed in the MAS.
I’m not sure why Xojo doesn’t use NSTask internally for it’s shells.

[quote=205578:@Marco Hof]Ok. lol
Well, a 08/15 is not allowed if you want your App sandboxed in the MAS.
I’m not sure why Xojo doesn’t use NSTask internally for it’s shells.[/quote]

Sorry to contradict, but almost all my 16 apps in the MAS use the plain Xojo shell, and two of them are UI skins for command lines. The legend of shell being forbidden in the MAS is completely bogus.

08/15 @ Wiki

Shell is fone for system provided console applications, but if you want to invoke a console application included within your application bundle, it must be Sandboxed; once it’s Sandboxed it can only be launched from NSTask and not the regular Xojo shell.

This is of course you want to ship your application on the Mac App Store.

[quote=205723:@Sam Rowlands]Shell is fone for system provided console applications, but if you want to invoke a console application included within your application bundle, it must be Sandboxed; once it’s Sandboxed it can only be launched from NSTask and not the regular Xojo shell.

This is of course you want to ship your application on the Mac App Store.[/quote]

Indeed, launching a Xojo console app from the standard shell withing a sandboxed application does not work.

[quote=205405:@Sam Rowlands]terminationHandler property takes a Obj-C Block

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/index.html#//apple_ref/occ/instp/NSTask/terminationHandler

As to why it’s crashing I don’t know, I’m using NSTask in my apps, but have never noticed a crash because of it.[/quote]

My rewrite of macoslib includes support for blocks. If Xojo ever resumes work in 2015 r3, I hope to make a beta version available.

Good news for MacOSLib users, it does seem like once Apple figured out how to do blocks, they went around inserting them where ever they could.

Without out native support for blocks within Xojo (Joe’s plugin really helps), it does make it harder to for declares.