dos
执行 DOS 命令并返回输出
对于与平台无关的代码,请使用 system
命令。
说明
示例
显示操作系统命令状态和输出
使用 cd
命令显示当前文件夹。status
为零表示命令已成功完成。MATLAB® 将在 cmdout
中返回一个包含当前文件夹的字符向量。
command = 'cd';
[status,cmdout] = dos(command)
输入参数
command
— 操作系统命令
字符串 | 字符向量
操作系统命令,指定为字符串或字符向量。该命令可以是打开用户界面的 Windows® UI 程序,也可以是您通常在 DOS 命令行窗口中运行的 DOS 控制台命令。该命令在 DOS shell 中执行,它可能不是您用于启动 MATLAB 的 shell。
示例: 'dir'
输出参数
status
— 命令退出状态
0 | 非零整数
命令退出状态,以 0
或非零整数的形式返回。当命令成功执行时,status
为 0
。否则,status
为非零整数。
如果
command
包含字符&
,则status
为command
启动时的退出状态。如果
command
不包含字符&
,则status
为command
命令完成时的退出状态。
cmdout
— 操作系统命令的输出
字符向量
操作系统命令的输出,以字符向量形式返回。系统 shell 可能无法正确表示非 Unicode® 字符。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)