PHP shell tar problem, return code 2
Want to archive a folder using tar from PHP:
$result = shell_exec("tar cf $sourceFile $sourceFolder -C $source > /dev/null; echo $?");
var_dump($result);
Output:
string(2) "2 "
the > /dev/null; echo $?
thing is for outputing the result code of a script under linux;
the -C $source
- changes to the right folder before doing anything
This is really strange because when i run this from linux console, it works just fine -开发者_Python百科 creates the archive, so it's not a permission issue.
Other sripts like "whoami" or "ls" work fine.
Any ideas what does it mean?
Maybe: shell_exec("/bin/bash tar ....")
Just for debugging purposes redirect stderr to stdout and use passthru() to display the complete output (possibly including error messages).
$cmd = sprintf("tar cf %s %s -C %s 2>&1",
escapeshellarg($sourceFile),
escapeshellarg($sourceFolder),
escapeshellarg($source)
);
echo '<pre>', htmlspecialchars($cmd), ": \n";
flush();
passthru($cmd, $code);
var_dump($code);
echo "</pre>";
精彩评论