`[command]…` output is prepended to exec `outStream`
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
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);
An example(s) of this causing a problem in the wild are available at hashicorp/setup-terraform#367.
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.