maxjackie
maxjackie

Reputation: 23312

When tried to run following PHP script gives error on Windows 7

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

Upvotes: 0

Views: 563

Answers (2)

Pozo
Pozo

Reputation: 1

$a = 'all';
file_put_contents('ip.txt',shell_exec($dump = sprintf('ipconfig /%s',$a)));

Upvotes: 0

lonesomeday
lonesomeday

Reputation: 237995

Try using escapeshellarg:

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

My guess is that you have shell metacharacters in $log.`

Upvotes: 2

Related Questions