codlib
codlib

Reputation: 638

Check status of tar command after running in shell_exec command?

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

Answers (1)

wallyk
wallyk

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

Related Questions