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?

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 17일

0 개 추천

try below. It just saves the screen outputs.
system('dir >output.txt')

댓글 수: 4

John F
John F 2011년 8월 17일
Works. It's been so long since I've had to remember the old DOS commands. Thanks!
Jason Ross
Jason Ross 2011년 8월 17일
Or if you honestly don't care about the screen output,
system('dir 1>NUL 2>NUL')
Will just send it off to the bit-bucket.
Fangjun Jiang
Fangjun Jiang 2011년 8월 17일
Thanks, Jason! Nice to know. Is this 1 and 2 refer to MATLAB fid 1 and 2?
Jason Ross
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
Helder Magalhães 2022년 1월 12일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

질문:

2011년 8월 17일

답변:

2022년 1월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by