MATLAB Function Reference Previous page   Next Page

Execute DOS command and return result



dos command calls upon the shell to execute the given command for Windows systems.

status = dos('command') returns completion status to the status variable.

[status,result] = dos('command') in addition to completion status, returns the result of the command to the result variable.

[status,result] = dos('command','-echo') forces the output to the Command Window, even though it is also being assigned into a variable.

Both console (DOS) programs and Windows programs may be executed, but the syntax causes different results based on the type of programs. Console programs have stdout and their output is returned to the result variable. They are always run in an iconified DOS or Command Prompt Window except as noted below. Console programs never execute in the background. Also, MATLAB will always wait for the stdout pipe to close before continuing execution. Windows programs may be executed in the background as they have no stdout.

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


The following example performs a directory listing, returning a zero (success) in s and the string containing the listing in w.

To open the DOS 5.0 editor in a DOS window

To open the notepad editor and return control immediately to MATLAB

The next example returns a one in s and an error message in w because foo is not a valid shell command.

This example echoes the results of the dir command to the Command Window as it executes as well as assigning the results to w.

See Also

! (exclamation point), perl, system, unix, winopen

Running External Programs in the MATLAB Desktop Tools and Development Environment documentation

Previous page  docsearch dot Next page

© 1994-2005 The MathWorks, Inc.