Parasol Framework
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Core
    • Display
    • Fluid
    • Font
    • Network
    • Vector
    • Audio
    • Sound
    • File
    • MetaClass
    • Module
    • StorageDevice
    • Task
    • Thread
    • Time
    • Compression
    • Config
    • Script
    • XML
    • Controller
    • BlurFX
    • ColourFX
    • CompositeFX
    • ConvolveFX
    • DisplacementFX
    • FilterEffect
    • FloodFX
    • ImageFX
    • LightingFX
    • MergeFX
    • MorphologyFX
    • OffsetFX
    • RemapFX
    • SourceFX
    • TurbulenceFX
    • WaveFunctionFX
    • Scintilla
    • ScintillaSearch
    • Bitmap
    • Clipboard
    • Display
    • Document
    • Font
    • Picture
    • Pointer
    • Surface
    • SVG
    • ClientSocket
    • HTTP
    • NetSocket
    • Proxy
    • Vector
    • VectorClip
    • VectorColour
    • VectorEllipse
    • VectorFilter
    • VectorGradient
    • VectorGroup
    • VectorImage
    • VectorPath
    • VectorPattern
    • VectorPolygon
    • VectorRectangle
    • VectorScene
    • VectorShape
    • VectorSpiral
    • VectorText
    • VectorTransition
    • VectorViewport
    • VectorWave

Task Class

System processes are managed by the Task class.

Tasks, also known as processes, form the basis of process execution in an operating system. By creating a task object, it is possible to execute a program from within the host system.

To execute a compiled program, set the Location field to point to the executable file before initialising the task. Arguments can be passed to the executable by setting the Parameters field. After initialising the task, use the Activate() action to run the executable. If the program executes successfully, the task object can be removed and this will not impact the running program.

The task object that represents the active process can be acquired from CurrentTask().

Structure

The Task class consists of the following fields:

Access
NameTypeComment
  ActionsAPTRUsed to gain direct access to a task's actions.

This field provides direct access to the actions of a task, and is intended for use with the active task object returned from CurrentTask(). Hooking into the action table allows the running executable to 'blend-in' with Parasol's object oriented design.

The Actions field points to a lookup table of ActionEntry items. Hooking into an action involves writing its AC index in the table with a pointer to the action routine. For example:

if (!AccessObject(CurrentTask(), 5000, &task)) {
   task->getPtr(FID_Actions, &actions);
   actions[AC::Seek] = PROGRAM_Seek;
   ReleaseObject(task);
}
  ArgsSTRINGCommand line arguments (string format).

This field allows command line arguments to be set using a single string, whereby each value is separated by whitespace. The string will be disassembled and the arguments will be available to read from the Parameters field.

If an argument needs to include whitespace, use double-quotes to encapsulate the value.

  ErrorCallbackFUNCTIONThis callback returns incoming data from STDERR.

The ErrorCallback field can be set with a function reference that will be called when an active process sends data via STDERR. The callback must follow the prototype Function(*Task, APTR Data, LONG Size)

The information read from STDERR will be returned in the Data pointer and the byte-length of the data will be indicated by the Size. The data pointer is temporary and will be invalid once the callback function has returned.

  ExitCallbackFUNCTIONThe callback is activated when the process is terminated.

The ExitCallback field can be set with a function reference that will be called when the executed process is terminated. The callback must follow the prototype Function(*Task).

Please keep in mind that if the Task is freed when the process is still executing, the ExitCallback routine will not be called on termination because the Task object no longer exists for the control of the process.

  FlagsTSFOptional flags.
NameDescription
TSF::ATTACHEDForces the new process to be attached to the parent (child will close when parent closes).
TSF::DETACHEDForces the new process to be detached from the parent.
TSF::PIPEEnable the output pipe to the launched process so that it can read data.
TSF::PRIVILEGEDThe child process will inherit the system privileges of its parent.
TSF::QUIETDivert all process output to /dev/null or the nearest equivalent for non-Unix systems.
TSF::RESET_PATHThe new process will start in its own folder and not the folder of the parent process.
TSF::SHELLEnables shell mode. On Unix systems, this means that a shell (usually BASH) will be used to launch the process.
TSF::VERBOSEEnable verbose logging.
TSF::WAITThe parent process will halt when the task is running. Control is returned to the parent process once the child process terminates.
  InputCallbackFUNCTIONThis callback returns incoming data from STDIN.

The InputCallback field is available to the active task object only (i.e. the current process). The referenced function will be called when process receives data from STDIN. The callback must follow the prototype Function(*Task, APTR Data, LONG Size, ERR Status)

The information read from STDOUT will be returned in the Data pointer and the byte-length of the data will be indicated by the Size. The data buffer is temporary and will be invalid once the callback function has returned.

A status of ERR::Finished is sent if the stdinput handle has been closed.

  LaunchPathSTRINGLaunched executables will start in the path specified here.

Use the LaunchPath field to specify the folder that a launched executable will start in when the task object is activated. This will override all other path options, such as the RESET_PATH flag.

  LocationSTRINGLocation of an executable file to launch.

When a task object is activated, the Location field will be checked for a valid filename. If the path is valid, the executable code will be loaded from this source. The source must be in an executable format recognised by the native platform.

Leading spaces will be ignored by the string parser. The Location string can be enclosed with quotes, in which case only the quoted portion of the string will be used as the source path.

  NameSTRINGName of the task.

This field specifies the name of the task or program that has been initialised. It is up to the developer of the program to set the Name which will appear in this field. If there is no name for the task then the system may assign a randomly generated name.

  OutputCallbackFUNCTIONThis callback returns incoming data from STDOUT.

The OutputCallback field can be set with a function reference that will be called when an active process sends data via STDOUT. The callback must follow the prototype Function(*Task, APTR Data, LONG Size)

The information read from STDOUT will be returned in the Data pointer and the byte-length of the data will be indicated by the Size. The Data pointer is temporary and will be invalid once the callback function has returned.

  Parameterspf::vector<std::string>Command line arguments (list format).

Command line arguments for a program can be defined here as a vector list, whereby each argument is an independent string. To illustrate, the following command-line string:

1> YourProgram PREFS MyPrefs -file "documents:readme.txt"

Would be represented as follows:

pf::vector<std::string> Args = {
   "PREFS",
   "MyPrefs",
   "-file",
   "documents:readme.txt"
};
  PathSTRINGThe current working folder of the active process.

The Path specifies the 'working folder' that determines where files are loaded from when an absolute path is not otherwise specified for file access. Initially the working folder is usually set to the folder of the parent process, such as that of a terminal shell.

The working folder can be changed at any time by updating the Path with a new folder location. If changing to the new folder fails for any reason, the working folder will remain unchanged and the path value will not be updated.

  PriorityINTThe task priority in relation to other tasks is be defined here.

Set the Priority field to change the priority of the process associated with the task. The default value for all processes is zero. High positive values will give the process more CPU time while negative values will yield CPU time to other active processes.

Note that depending on the platform, there may be limits as to whether one process can change the priority level of a foreign process. Other factors such as the scheduler used by the host system should be considered in the effect of prioritisation.

  ProcessIDINTReflects the process ID when an executable is launched.

If a task object launches an executable file via Activate(), the ProcessID will be set to the 'pid' that was assigned to the new process by the host system. At all other times the ProcessID is set to zero.

  ProcessPathSTRINGThe path of the executable that is associated with the task.

The ProcessPath is set to the path of the executable file that is associated with the task (not including the executable file name). This value is managed internally and cannot be altered.

In Microsoft Windows it is not always possible to determine the origins of an executable, in which case the ProcessPath is set to the working folder in use at the time the process was launched.

  ReturnCodeINTThe task's return code can be retrieved following execution.

Once a process has completed execution then its return code can be read from this field. If process is still running, the error code ERR::TaskStillExists will be returned.

  TimeOutDOUBLELimits the amount of time to wait for a launched process to return.

This field can be set in conjunction with the WAIT flag to define the time limit when waiting for a launched process to return. The time out is defined in seconds.

Actions

The following actions are currently supported:

ActivateActivating a task object will execute it.
ERR acActivate(*Object)

Activating a task results in the execution of the file referenced in the Location field.

On successful execution, the ProcessID will refer to the ID of the executed process. This ID is compatible with the hosting platform's unique process numbers.

If the WAIT flag is specified, this action will not return until the executed process has returned or the TimeOut (if specified) has expired. Messages are processed as normal during this time, ensuring that your process remains responsive while waiting.

The process' return code can be read from the ReturnCode field after the process has completed its execution.

In Microsoft Windows, output can be redirected to a file if the redirection symbol is used to direct output in one of the task arguments. For instance >C:\output.txt will redirect both stderr and stdout to c:\output.txt. The use of 1> to redirect stdout and 2> to redirect stderr independently of each other is also acceptable.

When running a DOS program in Microsoft Windows, the SHELL flag can be set in the Flags field to prevent the DOS window from appearing. The DOS window will also be hidden if the stdout or stderr pipes are redirected.

Error Codes
OkayOperation successful.
FailedGeneral failure.
TimeOutCan be returned if the WAIT flag is used. Indicates that the process was launched, but the timeout expired before the process returned.
FieldNotSetThe Location field has not been set.
GetKeyRetrieves custom key values.
ERR acGetKey(*Object, CSTRING Key, STRING Value, INT Size)
ParameterDescription
KeyThe name of a key value.
ValuePointer to a buffer space large enough to hold the retrieved value.
SizeIndicates the byte size of the Buffer.
SetKeyVariable fields are supported for the general storage of program variables.
ERR acSetKey(*Object, CSTRING Key, CSTRING Value)
ParameterDescription
KeyThe name of the target key.
ValueThe string value to associate with Key.
WriteSend raw data to a launched process' stdin descriptor.
ERR acWrite(*Object, APTR Buffer, INT Length, INT Result)
ParameterDescription
BufferA buffer containing the data that will be written to the object.
LengthThe total number of bytes to write to the object.
ResultThis parameter with be updated with the total number of bytes written from the Buffer.

If a process is successfully launched with the PIPE set in Flags, data can be sent to its stdin pipe by calling the Write() action. Setting the Buffer parameter to NULL will result in the pipe being closed (this will signal to the process that no more data is incoming).

Methods

The following methods are currently supported:

AddArgumentAdds a new argument to the Parameters field.
ERR task::AddArgument(OBJECTPTR Object, CSTRING Argument)
ParameterDescription
ArgumentThe new argument string.

This method will add a new argument to the end of the Parameters field array. If the string is surrounded by quotes, they will be removed automatically.

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
ExpungeForces a Task to expunge unused code.
ERR task::Expunge(OBJECTPTR Object)

The Expunge() method releases all loaded libraries that are no longer in use by the active process.

Error Codes
OkayOperation successful.
GetEnvRetrieves environment variables for the active process.
ERR task::GetEnv(OBJECTPTR Object, CSTRING Name, CSTRING * Value)
ParameterDescription
NameThe name of the environment variable to retrieve.
ValueThe value of the environment variable is returned in this parameter.

On platforms that support environment variables, GetEnv() returns the value of the environment variable matching the Name string. If there is no matching variable, ERR::DoesNotExist is returned.

In Windows, it is possible to look up registry keys if the string starts with one of the following (in all other cases, the system's environment variables are queried):

\HKEY_LOCAL_MACHINE\
\HKEY_CURRENT_USER\
\HKEY_CLASSES_ROOT\
\HKEY_USERS\

Here is a valid example for reading the 'Parasol' key value \HKEY_CURRENT_USER\Software\Parasol

Caution: If your programming language uses backslash as an escape character (true for Fluid developers), remember to use double-backslashes as the key value separator in your Name string.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function.
NoSupportThe platform does not support environment variables.
DoesNotExistThe environment variable is undefined.
QuitSends a quit message to a task.
ERR task::Quit(OBJECTPTR Object)

The Quit() method can be used as a convenient way of sending a task a quit message. This will normally result in the destruction of the task, so long as it is still functioning correctly and has been coded to respond to the MSGID::QUIT message type. It is legal for a task to ignore a quit request if it is programmed to stay alive.

Error Codes
OkayOperation successful.
SetEnvSets environment variables for the active process.
ERR task::SetEnv(OBJECTPTR Object, CSTRING Name, CSTRING Value)
ParameterDescription
NameThe name of the environment variable to set.
ValueThe value to assign to the environment variable.

On platforms that support environment variables, SetEnv() is used for defining values for named variables. A Name and accompanying Value string are required. If the Value is NULL, the environment variable is removed if it already exists.

In Windows, it is possible to set registry keys if the string starts with one of the following (in all other cases, the system's environment variables are queried):

\HKEY_LOCAL_MACHINE\
\HKEY_CURRENT_USER\
\HKEY_CLASSES_ROOT\
\HKEY_USERS\

When setting a registry key, the function will always set the Value as a string type unless the key already exists. If the existing key value is a number such as DWORD or QWORD, then the Value will be converted to an integer before the key is set.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function.
NoSupportThe platform does not support environment variables.
Task class documentation © Paul Manias 1996-2025

TSF Type

Task flags

NameDescription
TSF::ATTACHEDForces the new process to be attached to the parent (child will close when parent closes).
TSF::DETACHEDForces the new process to be detached from the parent.
TSF::PIPEEnable the output pipe to the launched process so that it can read data.
TSF::PRIVILEGEDThe child process will inherit the system privileges of its parent.
TSF::QUIETDivert all process output to /dev/null or the nearest equivalent for non-Unix systems.
TSF::RESET_PATHThe new process will start in its own folder and not the folder of the parent process.
TSF::SHELLEnables shell mode. On Unix systems, this means that a shell (usually BASH) will be used to launch the process.
TSF::VERBOSEEnable verbose logging.
TSF::WAITThe parent process will halt when the task is running. Control is returned to the parent process once the child process terminates.
Task module documentation © Paul Manias 1996-2025