Reputation: 638
I have a php script which is doing the following job.
$unTarCommand = 'tar -zxvf test.tar.gz';
$tarOutput = shell_exec($unTarCommand);
The code is working fine. Now the problem is when i am running the tar lists all files and it will get assigned to $tarOutput. So i am not able to identify whether tar runs without any error or not. Is there anyway to capture only the error in $tarOutput variable.
This code is part of a cron job.
Upvotes: 1
Views: 802
Reputation: 57774
Instead of shell_exec()
, use the exec
function:
The output assigned to a variable passed to the function, and the function's return value is what you need.
string exec ( string $command [, array &$output [, int &$return_var ]] )
Upvotes: 1