Skip to content

ToolRunner writes childprocess's both stderr and stdout to task's stdout. #1110

@gusega

Description

@gusega

Hi all,

Context

My task runs a command line application.

The application produces:

  1. normal output to stdout
  2. logs, messages, errors to stderr.

I want my task to write

  1. normal output of the application to a file
  2. logs messages, errors to the stderr or stdout, which will end up on the WEB UI console.

I write to the file by subscribing in my task to ToolRunner's stdout event, which is not optimal but works. Providing file WriteStream through options.outStream does not work, as ToolRunner would write both the application's stdout and stderr to that options.outStream.

The problem

When I provide my task a filename input parameter, I want it to print standard output to the file only.

But the task library always prints the standard command output to the console.

The only way for me to make it not do it is to enable silent mode. But silent mode has drawbacks, such as, I don't see the command name anymore when it starts and also stderr is gone. I can solve stderr issue by also subscribing to stderr event and printing errors manually.

Possible solution

Instead of using silent mode, ToolRunner writes command errors to error stream and normal output to stdout.

Basically, in ToolRunner, replace this :

if (!optionsNonNull.silent) {
    var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream! : optionsNonNull.outStream!;
    s.write(data);
}

with this:

if (!optionsNonNull.silent) {
   optionsNonNull.errStream!.write(data);
}

Then I can pass my file's WriteStream to options.outStream.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions