Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow easy selection of output interface (stdin/stderr) #107

Closed
mortenscheel opened this issue Feb 2, 2024 · 1 comment
Closed

Allow easy selection of output interface (stdin/stderr) #107

mortenscheel opened this issue Feb 2, 2024 · 1 comment

Comments

@mortenscheel
Copy link

Scenario: You have a command that outputs raw data (like json or csv) to the console, and it uses laravel/prompts. You want to save the output to a file, so you run php artisan some:command > path/to/file.json.
Unfortunately the prompt is using stdout, so it gets sent to the file and you don't see anything in the console.

I figured out a workaround that makes the prompt use stderr:

$output = $this->getOutput()->getOutput();
if ($output instanceof ConsoleOutputInterface) {
    Prompt::setOutput($output->getErrorOutput());
}

It works great, but it would be nice if there was an easier and more intuitive way of doing it. Maybe an optional argument that allows you to pass an OutputInterface, or a static Prompt::stderr() method. And maybe consider using stderr by default in the next major release, unless there are any drawbacks that I'm not aware of.

@driesvints
Copy link
Member

Heya, if you could send in a PR we could look at we can consider it maybe. Thanks for your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants