0

I need to capture the output of a console command to be sent by email as well when requested. How can I do this?

How do I get the output generated from the following $this->info() calls?

$r = processData();

$this->info("\nSubmitted data:");
$this->info("SubmissionId: " . $r['submission_id']);
$this->info("Status: " . $r['status']);
3
  • Does this answer help? Commented Nov 14, 2014 at 18:20
  • @lukasgeiter Unfortunately it doesn't because I need to capture a specific segment of the console output from with the executing command itself. The solution is for calling the command externally and capturing the output. Not sure how I would adapt it (I did try). Commented Nov 14, 2014 at 18:25
  • Okay. You could override the info method in your command (or a new command base class if you need it often) and then save it in there. Would that be an option? Commented Nov 14, 2014 at 18:30

2 Answers 2

0

Decided to just replace the $this->info() calls with a simple echo command and output buffer control. Looks good enough in the console and catches the data requested for emailing.

Example:

$r = processData();

if ($this->option('email-results'))
    ob_start();

echo "\nSubmitted data:";
echo "\nSubmissionId: " . $r['submission_id'];
echo "\nStatus: " . $r['status'];

if ($this->option('email-results')) {
    mail(
        $this->option('email-results'),
        'Results on ' . $start_time->toDateTimeString(),
        ob_get_contents()
    );

    ob_end_flush();
}
Sign up to request clarification or add additional context in comments.

1 Comment

I solved it with just overriding the info method and keeping track of a local protected buffer but still calling parent::info() for the console logging. $this->buffer .= $data . "\n";parent::info($data);
0

an Artisan method could help:

\Illuminate\Support\Facades\Artisan::output()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.