wscript.shell running file with space in path with PHP

Posted by ermac2014 on Stack Overflow See other posts from Stack Overflow or by ermac2014
Published on 2010-05-04T11:39:47Z Indexed on 2010/05/04 13:38 UTC
Read the original article Hit count: 248

Filed under:
|
|
|
|

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 :)

© Stack Overflow or respective owner

Related posts about php

Related posts about wscript