简体   繁体   中英

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.

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 ]] )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM