nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.4k stars 58 forks source link

Task command output redirect does not work #58

Closed Tradunsky closed 2 years ago

Tradunsky commented 2 years ago

Thanks for creating such a convenient tool 🙏🏻

One thing that is a bit confusing to me is command output redirect does not work:

>file: pyproject.toml
[tool.poe.tasks]
create-dotenv="echo 'VARIABLE=VALUE' > .env"

> poetry run poe create-dotenv
> ls -l .env
ls: .env: No such file or directory

Current workaround:

>file: pyproject.toml
[tool.poe.tasks]
create-dotenv="echo 'VARIABLE=VALUE'"

poetry run poe -q create-dotenv > .env

However, it does not play with chained tasks :(

nat-n commented 2 years ago

Hi @Tradunsky, thanks for the feedback.

The issue here is that by default tasks are of type cmd, meaning they're executed as direct subprocesses (without involving a shell).

You can get what you want (i.e. the ability to use POSIX shell syntax) by defining a task of type shell. You can specify the task type by declaring the task as a subtable, with the task type as the key containing the task content. TOML supports several different way of achieving this, the simplest looks like:

[tool.poe.tasks]
create-dotenv.shell = "echo 'VARIABLE=VALUE' > .env"

You can also change the default task type, though the trade off of using shell tasks is that they might not always work the same on windows since it doesn't always have a POSIX shell installed.

You'll find more details and examples in the README. I'll close this issue now, but feel free to reply if there's more to it.