Skip to content

Can't suppress stdout for echo #899

@wyardley

Description

@wyardley

Node version (or tell us if you're using electron or some other framework):

v8.11.3

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.2

Operating system:

Mac OS X

Description of the bug:

There doesn't seem to be a way to suppress stdout from echo() even when redirecting to another command / pipe.
Based on the code, it seems like no matter what, the call to sys.stdout.write() will happen.

shelljs/src/echo.js

Lines 58 to 60 in 4bd22e7

process.stdout.write(output);
return output;

Example ShellJS command to reproduce the error:

(given a file testfile without the string asdfasdf at the beginning of a line):

const shell = require('shelljs');

if (!shell.grep(/^asdfasdf/, 'testfile').stdout.trim()) {
  shell.echo({silent: true}, 'asdfasdf').toEnd('testfile');
}

In this case, whether {silent: true} (which it seems like it's supposed to be parsed, tho not do anything, based on

shelljs/src/echo.js

Lines 38 to 40 in 4bd22e7

}, {
silent: true,
});
) is there or not, the output is echoed and appended to testfile. Also, in this case, {silent: true} gets added to the file as well.

const shell = require('shelljs');

if (!shell.grep(/^asdfasdf/, 'testfile').stdout.trim()) {
  shell.config.silent = true;
  shell.echo('asdfasdf').toEnd('testfile');
}

The above code also doesn't suppress stdout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions