views:

243

answers:

1

I was trying to use wscript.shell through COM objects with php to pass some cmd commands to cURL library (the DOS version). here is what I use to perform this task:

function windExec($cmd,$mode=''){
    // Setup the command to run from "run"
    $cmdline = "cmd /C $cmd";

    // set-up the output and mode
    if ($mode=='FG'){
        $outputfile =  uniqid(time()) . ".txt";
        $cmdline .= " > $outputfile";
        $m = true;
    }
    else $m = false;

    // Make a new instance of the COM object
    $WshShell = new COM("WScript.Shell");

    // Make the command window but dont show it.
    $oExec = $WshShell->Run($cmdline, 0, $m);

    if ($outputfile){
        // Read the tmp file.
        $retStr = file_get_contents($outputfile);
        // Delete the temp_file.
         unlink($outputfile);
    }
    else $retStr = "";

    return $retStr;
}

now when I run this function like:

windExec("\"C:/Documents and Settings/ermac/Desktop/my project/curl\" http://www.google.com/", 'FG');

curl doesn't run because there is a problem with the path. but when I remove the spaces from the path it works great.

windExec("\"C:/curl\" http://www.google.com/", 'FG');

so my question is how can I escape these spaces in wscript.shell commands? is there anyway I can fix this?

thanks in advance :)

A: 

nvm I found a solution: there:

windExec("cd C:/Documents and Settings/ermac/Desktop/my project/libs & curl.exe -L http://www.google.com/", 'FG');
ermac2014