|MATLAB Function Reference|
Execute a DOS command and return result
calls upon the shell to execute the given command for Windows systems.
status = dos('command')
returns completion status to the
[status,result] = dos('command')
in addition to completion status, returns the result of the command to the
[status,result] = dos('command',' 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
&, 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
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
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.
! (exclamation point),