【问题标题】:When tried to run following PHP script gives error on Windows 7当尝试运行以下 PHP 脚本时,在 Windows 7 上出现错误
【发布时间】:2011-05-29 20:55:36
【问题描述】:
if (strlen($log) > 0)
{
    // Use "WScript.Shell" to run the command with no command prompt window pop up.
    $wShell = new COM("WScript.Shell"); 
    $cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";
    ////echo $cmd;
    $return = $wShell->Run($cmd, 0, true);
    if ($return == 0 || $return ==254)
    {
        $handle = @fopen(getenv('DIR') . "\\Temp\\event.log", "r");
        if ($handle)
        {
            $linenum = 1;
            while (!feof($handle))
            {
                $buffer = fgets($handle);
                // Skip the first three lines
                if ($linenum > 3)
                {
                    echo $buffer;
                }

                $linenum++;
            }

            fclose($handle);
        }
    }
    else
    {
        echo "Error running \"" . $cmd . "\" command."; 
    }
}

在 Windows 7 上出现错误:

错误:无法包含通用模块“CmdLib.Wsc”

当我尝试从命令行@ windows 7 运行它时,它工作正常:

cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1

【问题讨论】:

    标签: php windows-7 wsh


    【解决方案1】:

    尝试使用escapeshellarg

    $cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . escapeshellarg($log) . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";
    

    我的猜测是$log 中有 shell 元字符。`

    【讨论】:

      【解决方案2】:
      $a = 'all';
      file_put_contents('ip.txt',shell_exec($dump = sprintf('ipconfig /%s',$a)));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-04
        • 2022-10-08
        • 2019-01-26
        • 2019-01-15
        • 1970-01-01
        • 2017-03-28
        • 1970-01-01
        • 2021-12-21
        相关资源
        最近更新 更多