Skip to content

[Console] Progress bar is by default printed to stderr, changing output is complicated #18744

@zdenekdrahos

Description

@zdenekdrahos

Progressbar is by default redirected to stderr.
That's fine, if I could simple change output to stdout.

Example

Given errors from cron are logged to file:

* * * * *       app/console something 1> /dev/null 2>> app/logs/cron.log

After upgrade to symfony 2.8 the file contains:

$ cat app/logs/cron.log

 0/3 [>---------------------------]   0%
 1/3 [=========>------------------]  33%
 2/3 [==================>---------]  66%
 3/3 [============================] 100%

Why?

#15795 sets getErrorOutput in constructor. Provided solution:

If someone explicitly wants to use stdout, they can simply pass $output->getStream() instead of $output in most use-cases.

doesn't work because:

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Catchable Fatal Error: Argument 1 passed to Symfony\Component\Console\Helper\ProgressBar::__construct() must implement interface Symfony\Component\Console\Output\OutputInterface, resource given, called in /Users/www/ter_004_gosms/src/Analytics/Command/SmsReportingC
  ommand.php on line 41 and defined

Solution

Temporarily I solved it with creating another output:

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $stdout = new \Symfony\Component\Console\Output\StreamOutput($output->getStream());
        $progressBar = new ProgressBar($stdout);
    }

That's not very good developer experience. I had to search github issues, PR, symfony/console code...
Printing progress to stdout should be at least mentioned in documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions