当尝试在 Windows 7 上运行以下 PHP 脚本时出现错误
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
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.";
}
}
It gives an error on windows 7:
ERROR: Unable to include the common module"CmdLib.Wsc"
When I try run it from command line@ windows 7, it works fine:
cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
escapeshellarg
:我的猜测是你有
$log
中的 shell 元字符。`Try using
escapeshellarg
:My guess is that you have shell metacharacters in
$log
.`