MATLAB Function Reference |
Syntax
dos command
status = dos('command')
[status,result] = dos('command')
[status,result] = dos('command','-echo
')
Description
dos command
在Windows系統下呼叫外殼程序(shell)來執行指定的命令( calls upon the shell to execute the given command for Windows systems.)
status = dos('command')
回傳完成後的狀態給 status
變數。
[status,result] = dos('command')
除了完成後的狀態,也回傳執行指令所產生的結果給 result
變數。
[status,result] = dos('command','
將結果傳到變數中,並將輸出結果顯示在Command Window上。將結果傳到變數中。-echo
')
console (DOS) 程式和 Windows 程式都可以執行,但不同的語法可能產生不同的結果。Console programs
有 stdout
而且其輸出值會回傳到結果變數( 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
.
&
字元有特殊的意義。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.
Examples
下面範例中執行目前目錄的檔案清單,並回傳0(指令成功)給 s
和檔案清單給
w
。
[s, w] = dos('dir');
dos('edit &')
dos('notepad file.m &')
下面的範例中 s
得到回傳值1, w
得到錯誤訊息,因為 foo
不是正確的外殼程序(shell)指令。
[s, w] = dos('foo')
下面的範例將 dir
的結果同時顯示在Command Window中,同時存入w。
[s, w] = dos('dir', '-echo');
See Also
docopt | dot |