3

i have to extract the cabfile(.cab) on the server. i am Finding such script which extract cab file but i didn't get it yet. So now i am try to extract using cabarc.exe. But i face the problem that when i run command throuw commandline its work fine but when i give same command to system() or exec() function in php it is not work. code is as follow:

    $command = "c:\\exe\\cabarc X c:\\cab\\data.cab c:\\data\\";
if(($output = system($command,$return) != false)
{
  echo "$return";
}

it is not working when i use same string in commandline it works fine. please any body help me to why it not working what to do tomake it work is ther any rights issue. I had give the execute permission to the site.

thanks

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
jazzy
  • 31
  • 1

3 Answers3

1

The 2nd argument to the system function is passed by reference so it needs to be initialized by your code. Also, you should check for false using !== not != because it validates type in addition to value. Additionally, it looks like you've got an unbalanced parenthesis in your if statement. Try this:

$command = "c:\\exe\\cabarc X c:\\cab\\data.cab c:\\data\\";
$return = -1;
$output = system($command, $return);
if($output !== false)
{
    echo "Return value is: " . $return . "\r\n";
    echo "Output is:\r\n" . $output . "\r\n";
}

If that doesn't fix your issue, make sure the PHP user has permissions to access the file.

Asaph
  • 159,146
  • 25
  • 197
  • 199
  • Thanks Asaph for reply I have followed your suggestion. but my problem is still remaining. I have gave full control to the site and folder. but it doesn't work. Is ther any problem in php and iis? thanks for help – jazzy Nov 16 '09 at 15:06
  • @jazzy: Try running the PHP program outside of IIS. Try running the PHP program directly on the console. – Asaph Nov 16 '09 at 15:21
1

If you're using NTFS, check your file permissions and make sure the web server can run that executable, open the source file, and write the destination.

NeuroScr
  • 322
  • 1
  • 7
1

Another problem might be that the program is not allowed to run cmd.exe, maybe see if the IUSR account can execute this program as system needs to invoke a shell.

Martin
  • 5,945
  • 7
  • 50
  • 77