当我在节点中运行以下代码时:
var shell = require('shelljs');
var files = shell.ls('-R', './**/foobar');
console.log('Files found:\n' + files.join('\n'));
Run Code Online (Sandbox Code Playgroud)
我在输出中看到了这一点:
ls: no such file or directory: ./**/foobar
Run Code Online (Sandbox Code Playgroud)
如何抑制stderr,使其不被显示?
我花了点时间弄清楚了,但是您需要将shelljs配置为保持沉默,如下所示:
var shell = require('shelljs');
shell.config.silent = true;
Run Code Online (Sandbox Code Playgroud)
从README中,这是:
如果是
true,则禁止所有命令输出(echo()调用除外)。默认值为false。
| 归档时间: |
|
| 查看次数: |
300 次 |
| 最近记录: |