Exec command in php

exec command is not working else giving an empty response

$execute = ‘/bin/gunzip ’ . $file;
echo $execute;
//’/bin/gunzip xx.gz’
echo exec('/bin/gunzip ’ . $file ,$outarr);
print_r($outarr);

when the command is ‘/bin/gunzip -h’ i am getting the output

why is the command not working

expect an urgent reply

thnx in advance

is safemode enabled and/or is open basedir enabled, and/or is “exec” in the disable functions list ?
That might also be why it’s not working.

look for open_basedir, safe_mode and/or disable_functions in php.ini, or output the values using ini_get.


<?php
echo $file;
$path_parts = pathinfo($file);
$ext = $path_parts['extension'];
//echo $ext;
if($ext == 'gz')
{
  // Are you sure you're in the correct directory?
  // i.e. Are you sure PHP can find /../../XX.gz ?
  // and shouldn't it be ../../XX.gz ? i.e. a path relative to the current path
  // as opposed to an absolute path from the file system root?
  $execute = 'nohup /bin/gunzip ' . escapeshellarg('/../../XX.gz');
  echo $execute;
  echo exec($execute, $outarr);
  print_r($outarr);
}
?>

:slight_smile:

<?php
$path = ‘…/cj’;
$file = escapeshellarg(‘/…/…/xx.gz’);
echo $file;
$path_parts = pathinfo($file);
$ext = $path_parts[extension];
//echo $ext;
if($ext == ‘gz’)
{
$execute = ‘/bin/gunzip ’ . $file;// . ’ ’ . $path;
echo $execute;
echo exec(’/bin/gunzip - ’ . $file ,$outarr);//$execute,$outarr);
print_r($outarr);
//echo $retcode;
}
?>

i have given a relative path there

the command when executed in shell is perfect
y not in php

How is /…/…/XX.gz a relative path?
And what’s the - doing in the shell command?

well let me check it out

Thnx for u’r reply
<?php
$file = escapeshellarg(‘/…/…/XX.gz’);
echo $file;
$path_parts = pathinfo($file);
$ext = $path_parts[extension];
//echo $ext;
if($ext == ‘gz’)
{
$execute = '/bin/gunzip ’ . $file;// . ’ ’ . $path;
echo $execute;
echo exec('nohup /bin/gunzip - ’ . $file ,$outarr);//$execute,$outarr);
print_r($outarr);
//echo $retcode;
}
?>

I used it.
This is my code
Can u just help me out with this

but the
echo $execute;
which is in the if loop is working

You need to apply shellescapearg() after you do getfileinfo()
Otherwise the extension returned is gz", not gz and the if ($ext == ‘gz’) part doesn’t work.

So:


<?php
// $path = '../cj'; -- you're not using this, why define it?
echo $file;
$path_parts = pathinfo($file);
$ext = $path_parts[extension];
//echo $ext;
if($ext == 'gz')
{
$file = escapeshellarg('/home/zadmin/StrawberryNET_com_Skincare_Makeup_Cosmetics_Fragrance-StrawberryNET_US_Dollars_Product_Catalog.xml.gz');
$execute = '/bin/gunzip ' . $file;
echo $execute;
echo exec($execute, $outarr);
print_r($outarr);
//echo $retcode;
}
?>

You did do

echo ini_get(‘open_basedir’);
echo ini_get(‘safe_mode’);
echo ini_get(‘disable_functions’);

right?

Or better yet, var_dump() instead of echo

<?php
$path = ‘…/cj’;
$file = escapeshellarg(‘/home/zadmin/StrawberryNET_com_Skincare_Makeup_Cosmetics_Fragrance-StrawberryNET_US_Dollars_Product_Catalog.xml.gz’);
echo $file;
$path_parts = pathinfo($file);
$ext = $path_parts[extension];
//echo $ext;
if($ext == ‘gz’)
{
$execute = ‘/bin/gunzip ’ . $file;// . ’ ’ . $path;
echo $execute;
echo exec(’/bin/gunzip ’ . $file ,$outarr);//$execute,$outarr);
print_r($outarr);
//echo $retcode;
}
?>
THIS IS THE actual code

Have you applied escapeshellarg() to $file?
If not, you should :slight_smile:

i am getting an empty response for the ini_get