Simple example: whoami

One of the simplest yet useful examples of the oProcess Worker is to call out to the whoami executable in order to retrieve the username.

For this example, we will create a new variable object called proc and inherit from the oProcess Worker:

oProcess Worker Variable

Due to the simple nature of the command, we will reuse the current instance for the completion callbacks - we can do it by setting the $callbackinst property on the proc object to $cinst and create a $completed method in your class.

Next, we can call $init and $start on the proc object:

Do proc.$callbackinst.$assign($cinst)
Do proc.$init('whoami')
Do proc.$start()

Once the whoami executable finishes, a callback to your $completed method will be generated with a row as the first parameter containing two columns: retcode indicating the return code (ideally should be 0 for a successful outcome!) and runtime_seconds (which due to the speed of the command, might just be 0).

At this point, we know the process has finished executing and we're ready to retrieve our stdout by using $readlines():

Do proc.$readlines(kOProcessStdout) Returns myList

If we look into myList, we can see a stdout column containing the text written to the stdout during the process lifetime, which in our case is our username:

myList variable with stdout column