Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSTask/NSTask live output
Required plugins for this example: MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSTask/NSTask live output
This example is the version from Thu, 7th Dec 2016.
Project "NSTask live output.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
outputPipe = new NSPipeMBS
task = new MyTask
task.setStandardOutput outputPipe
task.launchPath = "/sbin/ping"
task.setArguments array("-c", "10", dest.Text.trim)
task.launch
outputHandle = outputPipe.fileHandleForReading
// async
return
// syncronously
'task.waitUntilExit
'finish
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control dest Inherits TextField
ControlInstance dest Inherits TextField
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
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 EventHandler
End Control
Sub Finish()
End Sub
Property outputHandle As NSFileHandleMBS
Property outputPipe As NSPipeMBS
Property task As MyTask
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
Class MyTask Inherits NSTaskMBS
EventHandler Sub Terminated()
MsgBox "terminated."
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCocoa Plugin.