Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSTask/NSTask
Function:
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
This example is the version from Mon, 9th Aug 2015.
Project "NSTask.rbp"
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 = LaunchPath.text 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 LaunchPath Inherits TextField
ControlInstance LaunchPath Inherits TextField
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Sub Finish() 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.Text = s end if 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." window1.Finish End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.




Links
MBS Xojo Plugins