Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

NSTaskMBS.arguments as string()
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: The command arguments that should be used to launch the executable.

Feedback, Comments & Corrections

NSTaskMBS.Constructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: The constructor.
Notes: On success the handle value is not zero.

Feedback, Comments & Corrections

NSTaskMBS.Destructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 15.3 Yes Yes Yes Yes No
Function: The destructor.

Feedback, Comments & Corrections

NSTaskMBS.environment as dictionary
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
property Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: A dictionary of variables for the environment from which the receiver was launched.
Notes:
The dictionary keys are the environment variable names.
(Read and Write computed property)

Feedback, Comments & Corrections

NSTaskMBS.interrupt
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sends an interrupt signal to the receiver and all of its subtasks.
Notes:
If the task terminates as a result, which is the default behavior, an NSTaskDidTerminateNotification gets sent to the default notification center. This method has no effect if the receiver was already launched and has already finished executing. If the receiver has not been launched yet, this method raises an NSInvalidArgumentException.
It is not always possible to interrupt the receiver because it might be ignoring the interrupt signal. interrupt sends SIGINT.

Feedback, Comments & Corrections

NSTaskMBS.launch
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Launches the task represented by the receiver.
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:
Raises an NSInvalidArgumentException if the launch path has not been set or is invalid or if it fails to create a process.
If you get an exception with posix_spawn and error 13, that's a permission denied.

Feedback, Comments & Corrections

NSTaskMBS.resume as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Resumes execution of the receiver task that had previously been suspended with a suspend message.
Notes: If multiple suspend messages were sent to the receiver, an equal number of resume messages must be sent before the task resumes execution.

Feedback, Comments & Corrections

NSTaskMBS.setArguments(arguments() as string)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the command arguments that should be used to launch the executable.
Example:
// Performing complex pipelines.
// You can create multiple NSTasks and a bunch of NSPipes and hook them together,
// or you can use the "sh -c" trick to feed a shell a command, and let it parse
// it and set up all the IPC. This pipeline cats /usr/share/dict/words, finds
// all the words with 'ham' in them, reverses them, and shows you the last 5.

dim task as new NSTaskMBS

task.LaunchPath="/bin/sh"

dim arguments(-1) as string

arguments.Append "-c"
arguments.Append "cat /usr/share/dict/words | grep -i ham | rev | tail -5"

task.setArguments arguments

Feedback, Comments & Corrections

NSTaskMBS.setStandardError(p as NSFileHandleMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard error for the receiver.
Notes:
This method can be used with NSPipeMBS or NSFileHandleMBS object.

If file is an NSPipe object, launching the receiver automatically closes the write end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the write end of the pipe won't be closed automatically.
If this method isn't used, the standard error is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.setStandardError(p as NSPipeMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard error for the receiver.
Notes:
This method can be used with NSPipeMBS or NSFileHandleMBS object.

If file is an NSPipe object, launching the receiver automatically closes the write end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the write end of the pipe won't be closed automatically.
If this method isn't used, the standard error is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.setStandardInput(p as NSFileHandleMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard input for the receiver.
Notes:
file: The standard input for the receiver, which can be either an NSFileHandle or an NSPipe object.

If file is an NSPipe object, launching the receiver automatically closes the read end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the read end of the pipe won't be closed automatically.
If this method isn't used, the standard input is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.setStandardInput(p as NSPipeMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard input for the receiver.
Notes:
file: The standard input for the receiver, which can be either an NSFileHandle or an NSPipe object.

If file is an NSPipe object, launching the receiver automatically closes the read end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the read end of the pipe won't be closed automatically.
If this method isn't used, the standard input is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.setStandardOutput(p as NSFileHandleMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard output for the receiver.
Notes:
file: The standard output for the receiver, which can be either an NSFileHandle or an NSPipe object.

If file is an NSPipe object, launching the receiver automatically closes the write end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the write end of the pipe won't be closed automatically.
If this method isn't used, the standard output is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.setStandardOutput(p as NSPipeMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sets the standard output for the receiver.
Notes:
file: The standard output for the receiver, which can be either an NSFileHandle or an NSPipe object.

If file is an NSPipe object, launching the receiver automatically closes the write end of the pipe in the current task. Don't create a handle for the pipe and pass that as the argument, or the write end of the pipe won't be closed automatically.
If this method isn't used, the standard output is inherited from the process that created the receiver. This method raises an NSInvalidArgumentException if the receiver has already been launched.

See also:

Feedback, Comments & Corrections

NSTaskMBS.standardError as Variant
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Returns the standard error file used by the receiver.
Notes:
The standard error file used by the receiver.

Standard error is where all diagnostic messages are sent. The object returned is either an NSFileHandle or an NSPipe instance, depending on what type of object was passed to setStandardError.

Feedback, Comments & Corrections

NSTaskMBS.standardInput as Variant
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Returns the standard input file used by the receiver.
Notes:
The standard input file used by the receiver.

Standard input is where the receiver takes its input from unless otherwise specified. The object returned is either an NSFileHandle or an NSPipe instance, depending on what type of object was passed to the setStandardInput method.

Feedback, Comments & Corrections

NSTaskMBS.standardOutput as Variant
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Returns the standard output file used by the receiver.
Notes: Standard output is where the receiver displays its output. The object returned is either an NSFileHandle or an NSPipe instance, depending on what type of object was passed to the setStandardOutput method.

Feedback, Comments & Corrections

NSTaskMBS.suspend as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Suspends execution of the receiver task.
Notes:
Returns true if the receiver was successfully suspended, false otherwise.

Multiple suspend messages can be sent, but they must be balanced with an equal number of resume messages before the task resumes execution.

Feedback, Comments & Corrections

NSTaskMBS.terminate
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Sends a terminate signal to the receiver and all of its subtasks.
Notes:
If the task terminates as a result, which is the default behavior, an NSTaskDidTerminateNotification gets sent to the default notification center. This method has no effect if the receiver was already launched and has already finished executing. If the receiver has not been launched yet, this method raises an NSInvalidArgumentException.
It is not always possible to terminate the receiver because it might be ignoring the terminate signal. terminate sends SIGTERM.

Feedback, Comments & Corrections

NSTaskMBS.waitUntilExit
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Tasks MBS MacCocoa Plugin 9.7 Yes No No Yes, macOS only No
Function: Block until the receiver is finished.
Example:
dim args(-1) as string
dim task as NSTaskMBS = NSTaskMBS.launchedTaskWithLaunchPath("/bin/ls", args)

task.waitUntilExit

MsgBox "done"
Notes: This method first checks to see if the receiver is still running using isRunning. Then it polls the current run loop using NSDefaultRunLoopMode until the task completes.

Feedback, Comments & Corrections

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





Links
MBS Xojo Plugins