Main Content

dos

Execute DOS command and return output

For platform-independent code, use the system command.

Description

[status,cmdout] = dos(command) calls the operating system to execute the specified command and returns the output of the DOS command to cmdout.

For more examples, tips, and information about limitations, see system.

example

Examples

collapse all

Display the current folder using the cd command. A status of zero indicates that the command completed successfully. MATLAB® returns a character vector containing the current folder in cmdout.

command = 'cd';
[status,cmdout] = dos(command)

Input Arguments

collapse all

Operating system command, specified as a string or a character vector. The command can be a Windows® UI program that opens a user interface, or a DOS console command that you typically run in a DOS command window. The command executes in a DOS shell, which might not be the shell from which you started MATLAB.

Example: 'dir'

Output Arguments

collapse all

Command exit status, returned as either 0 or a nonzero integer. When the command is successful, status is 0. Otherwise, status is a nonzero integer.

  • If command includes the ampersand character (&), then status is the exit status when command starts

  • If command does not include the ampersand character (&), then status is the exit status upon command completion.

Output of the operating system command, returned as a character vector. The system shell might not properly represent non-Unicode® characters.

Extended Capabilities

Version History

Introduced before R2006a