Suppressing command output
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John F
le 17 Août 2011
Réponse apportée : Helder Magalhães
le 12 Jan 2022
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 commentaires
Réponse acceptée
Fangjun Jiang
le 17 Août 2011
try below. It just saves the screen outputs.
system('dir >output.txt')
4 commentaires
Fangjun Jiang
le 17 Août 2011
Thanks, Jason! Nice to know. Is this 1 and 2 refer to MATLAB fid 1 and 2?
Jason Ross
le 17 Août 2011
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
Plus de réponses (1)
Helder Magalhães
le 12 Jan 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!