Navigation

Operators and Keywords

Function List:

C++ API

: system ("string")
: system ("string", return_output)
: system ("string", return_output, type)
: [status, output] = system (…)

Execute a shell command specified by string.

If the optional argument type is "async", the process is started in the background and the process ID of the child process is returned immediately. Otherwise, the child process is started and Octave waits until it exits. If the type argument is omitted, it defaults to the value "sync".

If system is called with one or more output arguments, or if the optional argument return_output is true and the subprocess is started synchronously, then the output from the command is returned as a variable. Otherwise, if the subprocess is executed synchronously, its output is sent to the standard output. To send the output of a command executed with system through the pager, use a command like

[~, text] = system ("cmd");
disp (text);

or

printf ("%s\n", nthargout (2, "system", "cmd"));

The system function can return two values. The first is the exit status of the command and the second is any output from the command that was written to the standard output stream. For example,

[status, output] = system ("echo foo; exit 2");

will set the variable output to the string ‘foo’, and the variable status to the integer ‘2’.

For commands run asynchronously, status is the process id of the command shell that is started to run the command.

See also: unix, dos.

Package: octave