KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: System Workers Callback Class.
PRODUCT: 4D | VERSION: 21 | PLATFORM: Mac & Win
Published On: March 2, 2026
The SystemWorker class in 4D allows calling external processes on the same machine as the 4D application. This class is now recommended over the command LAUNCH EXTERNAL PROCESS, as the SystemWorker class comes with a number of advantages, especially the asynchronous execution.

However, to achieve an asynchronous execution, the SystemWorker class must take the callbacks in the options arguments. For the callback function to be called, the process must be a worker created with CALL WORKER and not New Process.

First, make sure to run the process within a worker:

CALL WORKER("OpenSSL_Worker"; Current method name; $command; $onComplete)


Second, make a class to construct the options object when calling the SystemWorker. More info about these options is available in the documentation.

The following class is an example class to attend the callbacks from SystemWorker. Five functions are declared in this class constructor, and they all receive two parameters, as indicated in the comments of each function. Some functions, like onDataError or onData, might receive a third parameter containing actual data from the output stream. Finally, in this example, the timeout property is also included. Other options are available in the documentation above.

property timeout : Integer

Class constructor()
  This.timeout:=10

Function onResponse($param1 : Object; $param2 : Object)
  // $param1 = SystemWorker
  // $param2.type = "response"

Function onDataError($param1 : Object; $param2 : Object)
  // $param1 = SystemWorker
  // $param2.type = "error"
  // $param2.data = error data

Function onError($param1 : Object; $param2 : Object)
  // $param1 = SystemWorker
  // $param2.type = "error"

Function onData($param1 : Object; $param2 : Object)
  // $param1 = SystemWorker
  // $param2.type = "data"
  // $param2.data = received data

Function onTerminate($param1 : Object; $param2 : Object)
  // $param1 = SystemWorker
  // $param2.type = "termination"

Following is an example call to this class through the use of SystemWorker to execute an external process:

$callbacks:=cs.OpenSSLWorker.new()

$worker:=4D.SystemWorker.new($fullCommand; $callbacks)

This technical tip tries to showcase the basic minimum configuration to implemet system workers asynchronously in 4D.