帮助中心帮助中心
执行 UNIX 命令并返回输出
对于与平台无关的代码,请使用 system 命令。
system
[status,cmdout] = unix(command)
示例
[status,cmdout] = unix(command) 调用操作系统以执行指定的命令,并将命令的标准输出返回到 cmdout。
status
cmdout
command
MATLAB® 使用 shell 程序执行指定的命令。MATLAB 通过检查系统上的环境变量来确定使用哪个 shell 程序。MATLAB 首先检查 MATLAB_SHELL 变量,如果该变量为空或未定义,然后将检查 SHELL。如果 SHELL 也为空或未定义,则 MATLAB 将使用 /bin/sh。
MATLAB_SHELL
SHELL
/bin/sh
如需提示和有关限制的信息,请参阅 system。
全部折叠
使用 cd 命令显示当前文件夹。status 为零表示命令已成功完成。MATLAB 将在 cmdout 中返回一个包含当前文件夹的字符向量。
cd
command = 'cd'; [status,cmdout] = unix(command)
UNIX 命令,指定为字符向量。command 在 UNIX shell 中执行,后者可能不是您用于启动 MATLAB 的 shell。
示例: 'ls'
'ls'
命令退出状态,以 0 或非零整数的形式返回。当命令成功执行时,status 为 0。否则,status 为非零整数。
0
如果 command 包含字符 &,则 status 为 command 启动时的退出状态。
&
如果 command 不包含字符 &,则 status 为 command 命令完成时的退出状态。
操作系统命令的输出,以字符向量形式返回。系统 shell 可能无法正确表示非 Unicode® 字符。
在 R2006a 之前推出
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office