Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/GO/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Job
*/
private $id;

/**
* PID.
*
* @var string
*/
private $pid = null;

/**
* Command to execute.
*
Expand Down Expand Up @@ -174,6 +181,16 @@ public function __construct($command, $args = [], $id = null)
$this->args = $args;
}

/**
* Get the PID.
*
* @return string
*/
public function getPid()
{
return $this->pid;
}

/**
* Get the Job id.
*
Expand Down Expand Up @@ -303,8 +320,10 @@ public function compile()

// Add the boilerplate to redirect the output to file/s
if (count($this->outputTo) > 0) {
$compiled .= ' | tee ';
$compiled .= ' 2>&1 | tee ';

$compiled .= $this->outputMode === 'a' ? '-a ' : '';

foreach ($this->outputTo as $file) {
$compiled .= $file . ' ';
}
Expand All @@ -321,7 +340,7 @@ 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 &';
$compiled = '(' . $compiled . ') > /dev/null 2>&1 & echo $!';
}

return trim($compiled);
Expand Down Expand Up @@ -393,6 +412,7 @@ public function run()
$this->output = $this->exec($compiled);
} else {
exec($compiled, $this->output, $this->returnCode);
$this->pid = intval($this->output[0]);
}

$this->finalise();
Expand Down