toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

`[command]…` output is prepended to exec `outStream`

Open Swatinem opened this issue 5 years ago • 3 comments

Describe the bug I want to redirect a commands output to a file, but I still want the command that I execute to be logged. Currently the [command]… log is streamed into the outStream, and not to stdout as I would expect.

To Reproduce Steps to reproduce the behavior:

await exec.exec("echo", ["foobar"], { outStream: fs.createWriteStream("foobar.txt") });

Expected behavior I want the foobar.txt file to only have foobar in it. Instead, it will have the [command]echo foobar command output prepended.

Additional context

Not quite sure if this is intentional?

https://github.com/actions/toolkit/blob/2bf7365352507ee52b4017790934cf9cefabc5f4/packages/exec/src/toolrunner.ts#L424-L428

Swatinem avatar Nov 25 '20 08:11 Swatinem

It looks like the fix for this is to set the silent option to true, but that results in nothing being written to the outStream strangely.

I worked around this by doing two separate commands:

const { stdout } = await exec.getExecOutput(...);

fs.writeFile(filePath, stdout, options);

fearphage avatar Aug 12 '21 17:08 fearphage

An example(s) of this causing a problem in the wild are available at hashicorp/setup-terraform#367.

OJFord avatar Oct 26 '23 16:10 OJFord

getExecOutput workaround is not suitable in many cases because it stores entire output of a command in memory, so it cannot be used for piping large things.

matejdro avatar Dec 20 '24 06:12 matejdro