Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing NSTask in the background

I'm executing a shell script using NSTask but the problem is that the shell script is one of those scripts that keeps running until you press control+c. It starts up fine but then my mac application just waits for it to end. How can I make it so that it detaches the task from the mac application and goes and runs it in a background.

like image 290
ed1t Avatar asked Dec 31 '25 20:12

ed1t


1 Answers

Don't call waitUntilExit or otherwise run the task synchronously. If the task has lots of output, make sure you read and process the data or else an i/o buffer will fill and it'll block.

In general, you shouldn't be using NSTask for a daemon like operation anyway. You should be using launchd.

like image 144
bbum Avatar answered Jan 02 '26 10:01

bbum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!