and*_*vom 17 command-line octave
在Octave中,我可以抑制或隐藏指令的输出,在一行的末尾添加分号:
octave:1> exp([0 1])
ans = [ 1.0000 2.7183 ]
octave:2> exp([0 1]);
octave:3>
Run Code Online (Sandbox Code Playgroud)
现在,如果函数在返回值之前显示文本(例如使用disp()或print()),我该如何抑制输出?换句话说,我希望能够做到这一点:
disp("Starting...");
% hide text the may get displayed after this point
% ...
% show all text again after this point
disp("Done!");
Run Code Online (Sandbox Code Playgroud)
voi*_*hos 13
您可以修改PAGER变量(现在是一个函数)来重定向标准输出.在Unix系统上,您可以将其重定向到/dev/null.在Windows上,我尝试简单地重定向到一个什么都不做的Python程序,它运行得很好.(基本上,任何忽略输入的程序都会这样做)
PAGER('/dev/null');
page_screen_output(1);
page_output_immediately(1);
Run Code Online (Sandbox Code Playgroud)
完成后你可以改回来.并且可能将整个过程封装在一个函数中.
oldpager = PAGER('/dev/null');
oldpso = page_screen_output(1);
oldpoi = page_output_immediately(1);
% Call function here
PAGER(oldpager);
page_screen_output(oldpso);
page_output_immediately(oldpoi);
Run Code Online (Sandbox Code Playgroud)
您还可以非交互式地运行脚本,并正常重定向输出.
octave script.m > /dev/null
Run Code Online (Sandbox Code Playgroud)