Skip to Main Content Skip to Search
Product Documentation

system - Execute operating system command and return result

Syntax

system('command')
[status, result] = system('command')
[status,result] = system('command','-echo')

Description

system('command') calls the operating system to run the given command and directs the output to the MATLAB software. The command executes in a system shell, which might not be the shell from which you launched MATLAB.

[status, result] = system('command') returns completion status to the status variable and returns the result of the command to the result variable.

[status,result] = system('command','-echo') also forces the output to the Command Window.

The ampersand, &, character has special meaning. For console programs this causes the console to open. Omitting this character causes console programs to run iconically. For GUI programs, appending this character causes the application to run in the background. MATLAB continues processing.

This function is interchangeable with the dos and unix functions.

Examples

On a Windows system, display the current folder by accessing the operating system.

[status currdir] = system('cd')
status =
    0
currdir =
    D:\work\matlab\test
 

On a UNIX system, if you redirect stdin in the script and type at the keyboard while the script executes, MATLAB does not display the type-ahead characters.

[a,b] = system('cmd < /dev/null');

See Also

! (exclamation point) | computer | dos | perl | unix

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS