Skip to content

Commit 7f7da84

Browse files
committed
Availability to append scheduled command output
1 parent 435af15 commit 7f7da84

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class Event
8484
*/
8585
public $output = '/dev/null';
8686

87+
/**
88+
* Whether to append output to destination.
89+
*
90+
* @var bool
91+
*/
92+
protected $appendOutput = false;
93+
8794
/**
8895
* The array of callbacks to be run before the event is started.
8996
*
@@ -204,10 +211,12 @@ protected function callAfterCallbacks(Container $container)
204211
*/
205212
public function buildCommand()
206213
{
214+
$redirect = $this->appendOutput ? ' >> ' : ' > ';
215+
207216
if ($this->withoutOverlapping) {
208-
$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().') > '.$this->output.' 2>&1 &';
217+
$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().')'.$redirect.$this->output.' 2>&1 &';
209218
} else {
210-
$command = $this->command.' > '.$this->output.' 2>&1 &';
219+
$command = $this->command.$redirect.$this->output.' 2>&1 &';
211220
}
212221

213222
return $this->user ? 'sudo -u '.$this->user.' '.$command : $command;
@@ -647,6 +656,19 @@ public function sendOutputTo($location)
647656
return $this;
648657
}
649658

659+
/**
660+
* Whether to append output to destination.
661+
*
662+
* @param bool $append
663+
* @return $this
664+
*/
665+
public function appendOutput($append = true)
666+
{
667+
$this->appendOutput = $append;
668+
669+
return $this;
670+
}
671+
650672
/**
651673
* E-mail the results of the scheduled operation.
652674
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Illuminate\Console\Scheduling\Event;
4+
5+
class EventTest extends PHPUnit_Framework_TestCase
6+
{
7+
public function testBuildCommand()
8+
{
9+
$event = new Event('php -i');
10+
11+
$this->assertSame('php -i > /dev/null 2>&1 &', $event->buildCommand());
12+
}
13+
14+
public function testBuildCommandAppendOutput()
15+
{
16+
$event = new Event('php -i');
17+
18+
$event->appendOutput();
19+
$this->assertSame('php -i >> /dev/null 2>&1 &', $event->buildCommand());
20+
}
21+
}

0 commit comments

Comments
 (0)