This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Execute a command of the operating system

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


! command


system("command") executes a command of the operating system or a program, respectively.

!command is equivalent to system("command"):; note that !command will suppress output of its return value.

The syntax !command is allowed during interactive input only, not when reading MuPAD® input from a file. "!" must be the first character on the input line.

system is not available in all MuPAD versions. If not available, a call to system results in the following error message:

Error: Function not available for this client [system].

system("command") sends the command to the operating system. E.g., this command may start another application program on the computer. The return value 0 indicates that the command was executed successfully. Otherwise, an integer error code is returned which depends on the operating system and the command.

If the called command writes output to stderr on UNIX® systems, the output will go to the MuPAD stderr. Outputs on the standard output channel will be inserted in the command's output, but are not accessible programmatically.


Example 1

On a UNIX system, the date command is executed. The command output is printed to the screen, the error code 0 for successful execution is returned to the MuPAD session:

errorcode := system("date"):
Fri Sep 29 14:42:13 MEST 2000 

Now the date command is called with the command line option '+%m' in order to display the current month only:

errorcode := system("date '+%m'"):

Missing the prefix '+' in the command line option of date, date and therefore system returns an error code. Note that the error output goes to stderr:

system("date '%m'")

delete errorcode:

Example 2

The output of a program started with the system command cannot be accessed in MuPAD directly, but it can be redirected into a file and then be read using the read or ftextinput command:

system("echo communication example > comm_file"):

system("rm -f comm_file"):



A command of the operating system or a name of a program as a MuPAD character string

Return Values

"error code": an integer.

See Also

MuPAD Functions

Was this topic helpful?