Basic php: exec() question

	public function execute($cmd)
		// Some commands fail without sending output to cmdBuff.
		// This captures them to a text file in the task dir
		$fnErr = $this->taskDir . '_stderr.txt';
		file_put_contents($fnErr, PHP_EOL . $cmd . PHP_EOL, FILE_APPEND);
		exec("$cmd 2>>$fnErr", $this->cmdBuff, $rc);
		return $rc;

I am unhappy with this kludge.

“$cmd 2>&1” is not good enough. It is not capturing everything.
I hoped maybe some merciful guru here might know the better way…