在matlab中抑制输出到stderr
Suppress output to stderr in matlab
我试图抑制脚本中代码部分的输出(即来自 Caffe 网络的网络初始化)。我试过在 evalc
命令
中包装相应的代码位
[suppressed_output, var_output] = evalc('someFunction(input)');
但这不起作用。我仍然有大量来自网络初始化的(非错误)输出行阻塞了我的日志(在脚本中通过 fprintf('')
打印的所有想要的输出中)。我认为发生这种情况是因为相应的函数正在写入 STDERR
(而不是 STDOUT
?) - 它打印的第一行是此警告:
WARNING: Logging before InitGoogleLogging() is written to STDERR
... 然后是它正在做的数百行,例如:
I0215 15:01:51.840272 28620 upgrade_proto.cpp:66] Attempting to upgrade input file specified using deprecated input fields: tmp-def.prototxt
I0215 15:01:51.840360 28620 upgrade_proto.cpp:69] Successfully upgraded file specified using deprecated input fields.
...
我能以某种方式将输出抑制到 STDERR
(不弄乱函数内容)吗? 理想情况下只在本地用于此特定函数,因为我仍然喜欢获取潜在的错误消息。
如果相关:
我通过 matlab 命令行调用 myScript
并将其输出写入日志 (mlexec.log
) tee
:
matlab -nodesktop -nosplash -display :1 -r "try, myScript; catch e, disp(getReport(e)), end, quit force" 2>&1| tee mlexec.log
我想在评论中post这个,但它说我必须有 50 个声望(我现在有 49 个...)
我觉得this is what you're looking for
EDIT/UPDATE:
您可以做的一件事是用警告 on/off 语句附上一段代码,如下所示:
warning('off','all')
%your code here
warning('on','all')
这应该会停止从该部分向 stderr
输出任何警告。我个人不推荐这样做,很高兴知道你在做什么是 MATLAB 运行时不喜欢的。
这里的问题是,在 matlab 命令行调用中,来自 STDERR
的输出通过 "command": 2>&1
流式传输到 STDOUT
。由于 .cpp 文件似乎将其输出流式传输到 STDERR
(根据警告),它将被转发到 STDOUT
并最终转发到日志。
使用 2>NUL
或不同的日志文件(例如 2>mlexec.stderr.log
)将 STDERR
(2) 流式传输到 Nirvana 可解决问题。
我试图抑制脚本中代码部分的输出(即来自 Caffe 网络的网络初始化)。我试过在 evalc
命令
[suppressed_output, var_output] = evalc('someFunction(input)');
但这不起作用。我仍然有大量来自网络初始化的(非错误)输出行阻塞了我的日志(在脚本中通过 fprintf('')
打印的所有想要的输出中)。我认为发生这种情况是因为相应的函数正在写入 STDERR
(而不是 STDOUT
?) - 它打印的第一行是此警告:
WARNING: Logging before InitGoogleLogging() is written to STDERR
... 然后是它正在做的数百行,例如:
I0215 15:01:51.840272 28620 upgrade_proto.cpp:66] Attempting to upgrade input file specified using deprecated input fields: tmp-def.prototxt
I0215 15:01:51.840360 28620 upgrade_proto.cpp:69] Successfully upgraded file specified using deprecated input fields.
...
我能以某种方式将输出抑制到 STDERR
(不弄乱函数内容)吗? 理想情况下只在本地用于此特定函数,因为我仍然喜欢获取潜在的错误消息。
如果相关:
我通过 matlab 命令行调用 myScript
并将其输出写入日志 (mlexec.log
) tee
:
matlab -nodesktop -nosplash -display :1 -r "try, myScript; catch e, disp(getReport(e)), end, quit force" 2>&1| tee mlexec.log
我想在评论中post这个,但它说我必须有 50 个声望(我现在有 49 个...)
我觉得this is what you're looking for EDIT/UPDATE:
您可以做的一件事是用警告 on/off 语句附上一段代码,如下所示:
warning('off','all')
%your code here
warning('on','all')
这应该会停止从该部分向 stderr
输出任何警告。我个人不推荐这样做,很高兴知道你在做什么是 MATLAB 运行时不喜欢的。
这里的问题是,在 matlab 命令行调用中,来自 STDERR
的输出通过 "command": 2>&1
流式传输到 STDOUT
。由于 .cpp 文件似乎将其输出流式传输到 STDERR
(根据警告),它将被转发到 STDOUT
并最终转发到日志。
使用 2>NUL
或不同的日志文件(例如 2>mlexec.stderr.log
)将 STDERR
(2) 流式传输到 Nirvana 可解决问题。