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 に答える