9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/phancap.htm
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/phancap.htm
30 * Run a shell command and check exit code.
32 * @param string $cmd Full command including parameters and options
35 * @throws \Exception When the exit code is not 0
37 public static function run($cmd)
39 exec($cmd . ' 2>&1', $arOutput, $exitcode);
41 //FIXME: do something with $arOutput
42 echo implode("\n", $arOutput) . "\n";
43 throw new \Exception('Error running cutycapt', $exitcode);
48 * Let the command run for some time. Kill it if it did not exit itself.
50 * We use the GNU coreutils "timeout" utility instead of the pcntl
51 * extension since pcntl is disabled on mod_php.
53 * @param string $cmd Full command including parameters and options
56 * @throws \Exception When the exit code is not 0
58 public static function runForSomeTime($cmd, $seconds)
61 'timeout --signal=9 ' . $seconds . 's ' . $cmd