protected function initAndRunTaskInSubprocess($command)
{
if (function_exists('pcntl_fork')) {
// UNIX
$argv = explode(' ', $command);
list($task_name, $args, $options) = self::parseTaskAndParameters($argv);
$task_name = pakeTask::get_full_task_name($task_name);
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
}
if ($pid) {
// we are the parent
pcntl_wait($status);
$status = pcntl_wexitstatus($status);
if ($status == self::QUIT_INTERACTIVE) {
exit(0);
}
} else {
try {
$status = $this->initAndRunTask($task_name, $args, $options);
if (true === $status) {
exit(0);
}
exit($status);
} catch (pakeException $e) {
pakeException::render($e);
exit(1);
}
}
} else {
// WINDOWS or missing PCNTL functions
$php_exec = escapeshellarg((isset($_SERVER['_']) and substr($_SERVER['_'], -4) != 'pake') ? $_SERVER['_'] : 'php');
$force_tty = '';
if (pakeApp::isTTY()) {
$force_tty = ' --force-tty';
}
$pake_php = escapeshellarg($_SERVER['SCRIPT_NAME']);
$import_flag = ' --import=interactive';
system($php_exec . ' ' . $pake_php . $force_tty . $import_flag . ' ' . $command, $status);
if ($status == self::QUIT_INTERACTIVE) {
exit(0);
}
}
}