Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

NSTaskMBS class

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
Function: Using the NSTask class, your program can run another program as a subprocess and can monitor that program's execution.
Example:
// 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")

task.setArguments arguments

dim pipe as new NSPipeMBS

task.setStandardOutput pipe

dim file as NSFileHandleMBS = pipe.fileHandleForReading

task.launch

dim data as string = file.readDataToEndOfFile
dim text as string = DefineEncoding(data, encodings.UTF8)

MsgBox text
Notes:
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 REALbasic.

Feedback, Comments & Corrections

Quality of Service Constants

Constant Value Description
NSQualityOfServiceBackground &h09 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.
NSQualityOfServiceDefault -1 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.
NSQualityOfServiceUserInitiated &h19 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.
NSQualityOfServiceUserInteractive &h21 UserInteractive QoS is used for work directly involved in providing an interactive UI such as processing events or drawing to the screen.
NSQualityOfServiceUtility &h11 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:


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


NSTabViewMBS   -   NSTextAttachmentMBS




Links
MBS FileMaker Plugins