|Type||Topic||Plugin||Version||macOS||Windows||Linux||Console & Web||iOS|
|class||Cocoa Tasks||MBS MacCocoa Plugin||9.7||Yes||No||No||Yes, macOS only||No|
// Launch "ls -l -a -t" in the current directory, and then read the result into a string:
dim task as new NSTaskMBS
task.launchPath = "/bin/ls"
dim arguments(-1) as string = array("-l", "-a", "-t")
dim pipe as new NSPipeMBS
dim file as NSFileHandleMBS = pipe.fileHandleForReading
dim data as string = file.readDataToEndOfFile
dim text as string = DefineEncoding(data, encodings.UTF8)
An NSTask object creates a separate executable entity; it differs from NSThread in that it does not share memory space with the process that creates it.
A task operates within an environment defined by the current values for several items: the current directory, standard input, standard output, standard error, and the values of any environment variables. By default, an NSTask object inherits its environment from the process that launches it. If there are any values that should be different for the task, for example, if the current directory should change, you must change the value before you launch the task. A task's environment cannot be changed while it is running.
An NSTask object can only be run once. Subsequent attempts to run the task raise an error.
This class is comparable to the shell classe built into Xojo.
See also WindowsProcessMBS and WindowsShellExecuteMBS (Windows only), ConsoleExecuteMBS and ShellMBS (cross platform).
- event Terminated
- 9 properties
- property currentDirectoryPath as string
- property Handle as Integer
- property isRunning as boolean
- property launchPath as string
- property processIdentifier as Integer
- property qualityOfService as Integer
- property terminationReason as Integer
- property terminationStatus as Integer
- property environment as dictionary
- 19 methods
- method arguments as string()
- method Constructor
- method Destructor
- method interrupt
- method launch
- method resume as boolean
- method setArguments(arguments() as string)
- method setStandardError(p as NSFileHandleMBS)
- method setStandardError(p as NSPipeMBS)
- method setStandardInput(p as NSFileHandleMBS)
- method setStandardInput(p as NSPipeMBS)
- method setStandardOutput(p as NSFileHandleMBS)
- method setStandardOutput(p as NSPipeMBS)
- method standardError as Variant
- method standardInput as Variant
- method standardOutput as Variant
- method suspend as boolean
- method terminate
- method waitUntilExit
- 2 shared methods
- 7 constants
Quality of Service Constants
Background QoS is used for work that is not user initiated or visible. In general, a user is unaware that this work is even happening and it will run in the most efficient manner while giving the most deference to higher QoS work. For example, pre-fetching content, search indexing, backups, and syncing of data with external systems.
Default QoS indicates the absence of QoS information. Whenever possible QoS information will be inferred from other sources. If such inference is not possible, a QoS between UserInitiated and Utility will be used.
UserInitiated QoS is used for performing work that has been explicitly requested by the user and for which results must be immediately presented in order to allow for further user interaction. For example, loading an email after a user has selected it in a message list.
UserInteractive QoS is used for work directly involved in providing an interactive UI such as processing events or drawing to the screen.
Utility QoS is used for performing work which the user is unlikely to be immediately waiting for the results. This work may have been requested by the user or initiated automatically, does not prevent the user from further interaction, often operates at user-visible timescales and may have its progress indicated to the user by a non-modal progress indicator. This work will run in an energy-efficient manner, in deference to higher QoS work when resources are constrained. For example, periodic content updates or bulk file operations such as media import.
This class has no sub classes.
Some examples which use this class:
- /MacCocoa/NSTask/NSTask live output
- /MacCocoa/NSTask/NSTask traceroute
- /MacCocoa/NSTask/NSTask with Arguments
- /MacCocoa/readToEndOfFileInBackgroundAndNotify Test
The items on this page are in the following plugins: MBS MacCocoa Plugin.
MBS Xojo Plugins