system

Executes the shell command stringCommand. If executed in 'sync' mode or without additional inputs, the application waits until the execution is complete. If executed in 'async' mode, stringCommand is executed in a detached thread and control is returned to the application immediately.

Syntax

R1 =system(stringCommand)

[R1, R2] = system(stringCommand)

[R1, R2] = system(stringCommand, getoutput)

R1 = system(stringCommand, mode)

[R1, R2] = system(stringCommand, getoutput, mode)

Inputs

stringCommand
Command to be executed in the operating system shell.
Type: string
getoutput (optional)
If true, returns the output if mode is 'sync'. The default value is false.
Type: Boolean
mode (optional)
Controls how stringCommand is executed. If the value of mode is 'async', the system command is executed in asynchronous mode and the output is not returned. If the value of mode is 'sync', the system command is executed in synchronous mode, where the application waits until the stringCommand is terminated. The default value is 'sync'.
Type: string

Outputs

R1
The status of the system command executed. The process ID of the executed stringCommand is returned if the mode is 'async' .
Type: integer
R2 (optional)
Contains any text echoed to standard output when the system command is executed.
Type: string

Examples

Run the system command, without retrieving the output:
R = system('echo %date% %time%')
R = 0
Run the system command, with the text displayed to standard output:
[R1, R2] = system('echo %date% %time%')
R1 = 0
R2 = Fri 02/09/2018 12:24:58.52
Run the system command, retrieving the output:
[R1, R2] = system('echo %date% %time%', true, 'sync')
R1 = 0
R2 = Fri 02/09/2018 12:24:58.52
Run the system command, asynchronously:
R1 = system('notepad.exe', 'async')
R1 = 18300