sindresorhus / execa

Process execution for humans
MIT License
6.82k stars 215 forks source link

Support for double angle bracket >> #1164

Open TimCreasman opened 4 hours ago

TimCreasman commented 4 hours ago

Hello!

Apologies if I missed this in the documentation or the closed issues, but is there support for the >> redirection operator?

From my understanding, the single > bracket is essentially supported via the execa({stdout: {file: 'output.txt'}}) syntax but I couldn't find anything referencing >>.

>> is supposed to append the stdout to a file so maybe a syntax like execa({stdout: {append: 'output.txt'}}) would make sense?

ehmicky commented 3 hours ago

Hi @TimCreasman,

Execa does not use shells, so it does not use shell-specific syntax like >>. I think you did understand this, but I wanted to clarify, just in case.

That being said, we do try to emulate shell features. In this case, this would be appending to a file.

You can achieve this by doing:

await execa(..., {stdout: [createWriteStream('output.txt', {flags: 'a'}), 'pipe']})

Now, that's a little verbose, so we could maybe add the following syntax instead:

await execa(..., {stdout: {file: 'output.txt', append: true}})

What do you think @sindresorhus?

TimCreasman commented 2 hours ago

@ehmicky

Full disclosure, I did not understand that so thanks for the clarification. I see now this project essentially wraps node's child_process functionality (and if I had read the very first paragraph of this repo I would already have known that haha). I only just started using execa this week having moved from shelljs - loving it so far 👍

And thanks for the example! The second syntax example would be very nice but its good knowing the functionality is already easily available and not crazy verbose.