How to capture process stdout when it changes

Hey there,
I am sorry to compare to C# but that's the language I know. In C#, I could do something like

process.OutputDataReceived += new DataReceivedEventHandler(MyOutputHandler);

And then I could read the change in realtime. How can I achieve that in Swift MacOS app?

Try AsyncBytes, you can find the documentation here

AsyncBytes isn’t a great option for reading from pipes. Personally, I use Dispatch I/O for this. You can find a read-to-EOF example in Running a Child Process with Standard Input and Output on DevForums. Adapting that to deliver results as they arrive… well… it’s somewhere between easy and hard (-:

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Wow, I nevert hought I’m going to say it but it is one of a few instances when Windows programming is just that more pleasant