You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSTask/NSTask traceroute
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Domain Inherits TextField
ControlInstance Domain Inherits TextField
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control RunButton Inherits PushButton
ControlInstance RunButton Inherits PushButton
EventHandler Sub Action()
outputPipe = new NSPipeMBS
TextArea1.Text = ""
task = new NSTaskMBS
task.setStandardOutput outputPipe
task.setArguments array(domain.text)
task.launchPath = "/usr/sbin/traceroute"
task.launch
outputHandle = outputPipe.fileHandleForReading
// async
timer1.mode = timer.ModeMultiple
return
End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if task <> nil then
ReadSomeData
if not task.isRunning then
// done
me.Mode = timer.ModeOff
end if
end if
End EventHandler
End Control
Sub ReadSomeData()
if outputHandle <> nil then
dim data as MemoryBlock = outputHandle.readDataOfLength(outputHandle.AvailableBytes)
if data <> nil then
dim s as string = DefineEncoding(data, encodings.UTF8)
s = ReplaceLineEndings(s, EndOfLine)
TextArea1.AppendText s
end if
end if
End Sub
Property outputHandle As NSFileHandleMBS
Property outputPipe As NSPipeMBS
Property task As NSTaskMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar