/** * Execute the command. * * @param Command $command * @param bool $background * * @return null|string|array */ public function execute(Command $command, $background = false) { $cmd = $command->getCommandLine(); if ($background) { $WshShell = new \COM("WScript.Shell"); return $WshShell->Run($cmd, 7, false); } else { exec($cmd, $exec); return $exec; } }
public function testProcessBackground() { $cmd = new Command('php', __DIR__ . '/command/basic.php'); $this->assertEquals('php ' . __DIR__ . '/command/basic.php', $cmd->getCommandLine()); $cmd->exec(true); $processes = System::processes('php'); $this->assertEquals(count($processes), Manager::os()->countProcesses('php')); $this->assertTrue(is_array($processes)); $this->assertEquals(2, count($processes)); $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[0]); $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[1]); $processes[1]->kill(); }
public function testKill() { $cmd = new Command('php', __DIR__ . '/command/basic.php'); if (\Ark4ne\Processes\System\OS\Manager::isWin()) { $this->assertNull($cmd->exec(true)); } else { $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $cmd->exec(true)); } $processes = System::processes('php'); $this->assertEquals(2, count($processes)); $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $processes[0]); $processes[1]->kill(); $processes = System::processes('php'); $this->assertEquals(1, count($processes)); }
public function testExecBackground() { if (\Ark4ne\Processes\System\OS\Manager::isLinux()) { $command = new Command('php', __DIR__ . '/command/basic.php'); $this->assertInstanceOf('\\Ark4ne\\Processes\\Process\\Process', $command->exec(true)); } if (\Ark4ne\Processes\System\OS\Manager::isWin()) { $command = new Command('php', __DIR__ . '\\command\\basic.php'); $this->assertNull($command->exec(true)); } }
/** * Execute the command. * * @param Command $command * @param bool $background * * @return null|string * @throws CommandEmptyException */ public function execute(Command $command, $background = false) { exec($command->getCommandLine() . ($background ? ' > /dev/null 2>&1 & echo $!' : ''), $exec); return $background ? $exec[0] : $exec; }