Skip to content

Implementation

When it comes to implementing the oProcess Worker, your approach depends on your objectives: either wrapping around an executable or executing a command (e.g. via bash or PowerShell).

Wrapping around an executable

For the purpose of wrapping an executable so it can be invoked directly from your Omnis application, we suggest creating a new object class within your library that inherits from the oProcess Worker via the $superclass property.

This method allows you to build an object class tailored to your executable's needs. For instance, your could build a comprehensive wrapper for the git executable in your new object class.

Executing a command

If your goals is to just execute a command, the process is more straightforward. Create a new object variable in your class which inherits from the oProcess Worker and use its methods to call your executable.

While this method offers less control over the process, it can perfectly handle simpler tasks like invoking a bash command such as whoami to retrieve the current username.

Further details

Once you have an instance of the oProcess Worker, you can start using through its $init and $run (runs on main thread, blocking) or $start (runs on background thread, non-blocking).

The $init method takes 4 arguments: a character variable for the process to execute, an optional character variable for arguments to pass to the process, an optional character variable for the initial directory and an optional two-column list of environment variables.

For example, the following call to initialise, when started, will result in a callback to $stdout with the "Hello world!" message in the stdout column of the receiving row parameter, which has been taken out of the TEST environment variable given:

Do proc.$init('/bin/echo $TEST',,,list(row("TEST","Hello world!")))

For further details regarding the oProcess Worker methods and properties, please visit our online documentation here.