0

我试图通过带有 php 的 COM 对象使用 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');

curl 没有运行,因为路径有问题。但是当我从路径中删除空格时,效果很好。

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

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

提前致谢 :)

4

1 回答 1

0

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

windExec("cd C:/Documents and Settings/ermac/Desktop/my project/libs & curl.exe -L http://www.google.com/", 'FG');
于 2010-05-04T13:36:58.747 回答