diff --git a/src/GO/Job.php b/src/GO/Job.php index 5646c0f..71de647 100644 --- a/src/GO/Job.php +++ b/src/GO/Job.php @@ -308,7 +308,12 @@ public function compile() if ($this->canRunInBackground()) { // Parentheses are need execute the chain of commands in a subshell // that can then run in background - $compiled = '(' . $compiled . ') > /dev/null 2>&1 &'; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $compiled = '(' . $compiled . ') > NUL 2>&1 &'; + } + else { + $compiled = '(' . $compiled . ') > /dev/null 2>&1 &'; + } } return trim($compiled); diff --git a/tests/GO/JobTest.php b/tests/GO/JobTest.php index 7720e45..ef67c27 100644 --- a/tests/GO/JobTest.php +++ b/tests/GO/JobTest.php @@ -88,15 +88,27 @@ public function testShouldCompileWithArguments() $this->assertEquals("ls '-l' '-arg' 'value'", $job->inForeground()->compile()); } - - public function testShouldCompileCommandInBackground() + + public function testShouldCompileUnixCommandInBackground() { + $this->assertFalse(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); + $job1 = new Job('ls'); $job1->at('* * * * *'); - + $this->assertEquals('(ls) > /dev/null 2>&1 &', $job1->compile()); } - + + public function testShouldCompileWinCommandInBackground() + { + $this->assertTrue(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); + + $job1 = new Job('dir'); + $job1->at('* * * * *'); + + $this->assertEquals('(dir) > NUL 2>&1 &', $job1->compile()); + } + public function testShouldRunInBackground() { // This script has a 5 seconds sleep