wscript.shell运行带有PHP空间路径的文件

时间:2010-05-04 11:39:48

标签: php shell path spaces wsh

我试图通过COM对象与php一起使用wscript.shell将一些cmd命令传递给cURL库(DOS版本)。这是我用来执行此任务的内容:

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;
}

现在当我运行这个函数时:

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

卷曲不会运行,因为路径存在问题。但当我从路径中删除空格时,它的效果很好。

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

所以我的问题是如何在wscript.shell命令中转义这些空格? 无论如何我能解决这个问题吗?

提前感谢:)

1 个答案:

答案 0 :(得分:0)

nvm我找到了一个解决方案: 有:

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