如何抑制以八度为单位的命令输出? [英] How can I suppress the output of a command in octave?

查看:80
本文介绍了如何抑制以八度为单位的命令输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在八度中,我可以抑制或隐藏在行尾添加分号的指令的输出:

In Octave I can suppress or hide the output of an instruction adding a semicolon to the end of a line:

octave:1> exp([0 1])
ans = [ 1.0000   2.7183 ]
octave:2> exp([0 1]);
octave:3> 

现在,如果函数在返回其值之前显示文本(例如,使用disp()print()),该如何抑制输出?换句话说,我希望能够做到这一点:

Now, how can I suppress the output if the function displays text (e.g. using disp() or print()) before returning its value? In other words, I want to be able to do this:

disp("Starting...");
% hide text the may get displayed after this point
% ...
% show all text again after this point
disp("Done!");

推荐答案

您可以修改PAGER变量(现在是函数)以重定向标准输出.在Unix系统上,您可以将其重定向到/dev/null.在Windows上,我尝试仅重定向到不执行任何操作的Python程序,并且该程序运行良好. (基本上,任何忽略输入的程序都可以)

You can modify the PAGER variable (which is now a function) to redirect standard output. On Unix systems, you can redirect it to /dev/null. On Windows, I tried simply redirecting to a Python program that does nothing, and it works decently. (Basically, any program that ignores the input will do)

PAGER('/dev/null');
page_screen_output(1);
page_output_immediately(1);

完成后,您只需将其更改回即可.也许将整个过程封装在一个函数中.

You can just change it back after you're done. And maybe encapsulate this whole procedure in a function.

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);

您还可以简单地以非交互方式运行脚本,然后正常重定向输出.

You can also simply run your scripts non-interactively, and redirect the output normally.

octave script.m > /dev/null

这篇关于如何抑制以八度为单位的命令输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆