Suppressing command output
6 次查看(过去 30 天)
显示 更早的评论
I am using the function "system(<SOME COMMAND>)" in a function. The command I'm calling has a lot of screen outputs that I'd like to suppress. How can I do that?
0 个评论
采纳的回答
Fangjun Jiang
2011-8-17
try below. It just saves the screen outputs.
system('dir >output.txt')
4 个评论
Jason Ross
2011-8-17
I've always thought of it as stdout (1) and stderr (2). I've used this extensively outside of MATLAB for other scripting duties. There's a nice summary of redirection commmands at
http://www.robvanderwoude.com/redirection.php
更多回答(1 个)
Helder Magalhães
2022-1-12
It's also possible to use "system" (console) based filtering to avoid the whole output to be redirected to Matlab. For example, taking a directory listing in Windows environment:
% the first part only lists text files, including details
% the part after the pipe filters relevant lines
% (to only dump filenames, use 'dir /b' instead)
sys_cmd = 'dir "C:\MyDirectory\*.txt" | find ".txt"';
system(sys_cmd, '-echo');
I wouldn't generally recommend using system calls often, as it may easily break the possibility of porting your software/environment to another platform. But for quick experiments/diagnostics it can become very handy, specially if one is familiar with command-line environment.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!