SKTask Reference

File
ShellKit/SKTask.h
Copyright
© (c) 2017, Jean-David Gadina - www.xs-labs.com
Date
Monday, May 15, 2017

Class SKTask

Attributes

Conforms to
SKRunableObject
Superclass
SKObject

- initWithShellScript:

Creates a task from a shell script

- ( instancetype )initWithShellScript: ( NSString * )script;

Parameters
  • script
    The shell script to execute when the task is run
Return value

The task object

- initWithShellScript:recoverTask:

Creates a task from a shell script

- ( instancetype )initWithShellScript: ( NSString * )script recoverTask: ( nullable SKTask * )recover;

Discussion

If a recovery task is passed, it will be executed upon failure. If the recovery task then succeed, the primary task will also succeed.

Parameters
  • script
    The shell script to execute when the task is run
  • recover
    An optional task to execute as recovery if the task fails.
Return value

The task object

- initWithShellScript:recoverTasks:

Creates a task from a shell script

- ( instancetype )initWithShellScript: ( NSString * )script recoverTasks: ( nullable NSArray< SKTask * > * )recover NS_DESIGNATED_INITIALIZER;

Discussion

If recovery tasks are passed, they will be executed upon failure, until one of them succeed. If a recovery task then succeed, the primary task will also succeed.

Parameters
  • script
    The shell script to execute when the task is run
  • recover
    An optional array of tasks to execute as recovery if the task fails.
Return value

The task object

+ taskWithShellScript:

Creates a task from a shell script

+ ( instancetype )taskWithShellScript: ( NSString * )script;

Parameters
  • script
    The shell script to execute when the task is run
Return value

The task object

+ taskWithShellScript:recoverTask:

Creates a task from a shell script

+ ( instancetype )taskWithShellScript: ( NSString * )script recoverTask: ( nullable SKTask * )recover;

Discussion

If a recovery task is passed, it will be executed upon failure. If the recovery task then succeed, the primary task will also succeed.

Parameters
  • script
    The shell script to execute when the task is run
  • recover
    An optional task to execute as recovery if the task fails.
Return value

The task object

+ taskWithShellScript:recoverTasks:

Creates a task from a shell script

+ ( instancetype )taskWithShellScript: ( NSString * )script recoverTasks: ( nullable NSArray< SKTask * > * )recover;

Discussion

If recovery tasks are passed, they will be executed upon failure, until one of them succeed. If a recovery task then succeed, the primary task will also succeed.

Parameters
  • script
    The shell script to execute when the task is run
  • recover
    An optional array of tasks to execute as recovery if the task fails.
Return value

The task object

delegate

The task's delegate

@property( atomic, readwrite, weak ) id< SKTaskDelegate > delegate;

See also

Protocol SKTaskDelegate

Attributes

Extends Protocol
NSObject

- task:didEndWithStatus:

Called when a task has finished running @dicussion This method is optional.

- ( void )task: ( SKTask * )task didEndWithStatus: ( int )status;

Parameters
  • task
    The task object
  • status
    The task's exit status
See also
Notes: This method is optional.

- task:didProduceOutput:

Called when a task has produced output on `stdout` or `stderr` @dicussion This method is optional. Note that the output may not be whole/complete lines, as this method, if implemented by the delagete, will be called as output is captured.

- ( void )task: ( SKTask * )task didProduceOutput: ( NSString * )output forType: ( SKTaskOutputType )type;

Parameters
  • task
    The task object
  • output
    The produced output string
  • type
    The output type
See also
Notes: This method is optional.

- task:didProduceOutput:forType:

Called when a task has produced output on `stdout` or `stderr` @dicussion This method is optional. Note that the output may not be whole/complete lines, as this method, if implemented by the delagete, will be called as output is captured.

- ( void )task: ( SKTask * )task didProduceOutput: ( NSString * )output forType: ( SKTaskOutputType )type;

Parameters
  • task
    The task object
  • output
    The produced output string
  • type
    The output type
Notes: This method is optional.

- taskWillStart:

Called when a task is about to be run @dicussion This method is optional.

- ( void )taskWillStart: ( SKTask * )task;

Parameters
  • task
    The task object
See also
Notes: This method is optional.

Types

NS_ENUM

The type of output of a task

typedef NS_ENUM( NSInteger, SKTaskOutputType ) { SKTaskOutputTypeStandardOutput, SKTaskOutputTypeStandardError };

Discussion

Used to differenciate output comming from a task's `stdout` or `stderr`.

Parameters
  • SKTaskOutputTypeStandardOutput
    `stdout` output type
  • SKTaskOutputTypeStandardError
    `stderr` output type

SKTaskOutputType

The type of output of a task

typedef NS_ENUM( NSInteger, SKTaskOutputType ) { SKTaskOutputTypeStandardOutput, SKTaskOutputTypeStandardError };

Discussion

Used to differenciate output comming from a task's `stdout` or `stderr`.

Parameters
  • SKTaskOutputTypeStandardOutput
    `stdout` output type
  • SKTaskOutputTypeStandardError
    `stderr` output type