System () does not work in php using Windows Server 2003

I need to extract cabfile (.cab) on the server. I find a script that retrieves the cab file, but I haven't received it yet. So now I'm trying to extract using cabarc.exe. But I ran into the problem that when I run the command prompt command line, its work is fine, but when I provide the same command to the system () or exec () function in php, it does not work. The code is as follows:

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

It does not work, when I use the same line on the command line, it works fine. please, any body will help me why it does not work, what to do if it works, this is any problem. I gave permission to execute on the site.

thanks

+3
source share
3 answers

The second argument to the system function is passed by reference, so its code must be initialized. In addition, you should check false using !==not !=, because it checks the type in addition to the value. Also, it looks like you have an unbalanced bracket in the instruction if. Try the following:

$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 this does not fix your problem, make sure that the PHP user has permissions to access the file.

+1
source

If you are using NTFS, check the file permissions and make sure that the web server can run this executable file, open the source file and record the destination.

+1
source

, cmd.exe, , , IUSR , .

+1

Source: https://habr.com/ru/post/1722997/


All Articles