system() 无法在使用 Windows Server 2003 的 php 中工作

发布于 2024-08-11 11:01:35 字数 437 浏览 4 评论 0原文

我必须在服务器上提取 cabfile(.cab)。 我正在寻找这样的脚本来提取 cab 文件,但我还没有得到它。 所以现在我尝试使用 cabarc.exe 进行提取。 但我面临的问题是,当我通过命令行运行命令时,它工作正常,但是当我向 php 中的 system() 或 exec() 函数发出相同的命令时,它不起作用。 代码如下:

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

当我在命令行中使用相同的字符串时它不起作用,它工作正常。 请任何机构帮助我,为什么它不起作用,该怎么做才能使它起作用,是否有任何权利问题。 我已授予该站点执行权限。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晒暮凉 2024-08-18 11:01:35

system 函数的第二个参数是通过引用传递的,因此需要由您的代码初始化。另外,您应该使用 !== 而不是 != 检查 false,因为它除了验证值之外还验证类型。此外,您的 if 语句中的括号似乎不平衡。试试这个:

$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";
}

如果这不能解决您的问题,请确保 PHP 用户有权访问该文件。

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.

止于盛夏 2024-08-18 11:01:35

如果您使用的是 NTFS,请检查您的文件权限并确保 Web 服务器可以运行该可执行文件、打开源文件并写入目标。

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.

揪着可爱 2024-08-18 11:01:35

另一个问题可能是该程序不允许运行cmd.exe,也许看看IUSR帐户是否可以执行该程序,因为系统需要调用shell。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文