14

私はpowershellスクリプトからプロセスを開始し、そのようなパラメータを渡す必要があります: -a -s f1d:\some directory\with blanks in a path\file.iss それを行うには、次のコードを書きます:

$process = [System.Diagnostics.Process]::Start("$setupFilePath", '-a -s -f1"d:\some directory\with blanks in a path\fileVCCS.iss"') 
$process.WaitForExit()

その結果、プロセスは開始されますが、最後の引数: -f1d:\some directory\with blanks in a path\file.iss が正しく渡されません。助けてください

4

3 に答える 3

10

私はあなたが使用できると思いますStart-Process

Start-Process -FilePath $setupFilePath -ArgumentList '-a','-s','-f1"d:\some directory\with blanks in a path\fileVCCS.iss"' |
    Wait-Process
于 2013-07-10T03:49:08.440 に答える
5

あなたの質問は次のように理解しています: 引数の1つにスペースがあるプロセスを開始するために複数の引数を渡す方法は?

Windows バッチ ファイルに相当するものは次のようになると想定しています。

"%setupFilePath%" -a -s -f1"d:\some directory\with blanks in a path\fileVCCS.iss"

ここで、二重引用符により、受信プロセス (この場合はsetupFilePath ) が 3 つの引数を受け取ることができます。

  1. -a
  2. -s
  3. -f1"d:\some directory\with blanks in a path\fileVCCS.iss"

あなたの質問のコードスニペットでこれを達成するには、バックティック(1 の左側でエスケープキーの下にあり、一重引用符と混同しないでください。別名 Grave-accent)を使用して、このような内側の二重引用符をエスケープします:

$process = [System.Diagnostics.Process]::Start("$setupFilePath", "-a -s -f1`"d:\some directory\with blanks in a path\fileVCCS.iss`"") 
$process.WaitForExit()

バックティックの使用に加えて、引数リストを囲む一重引用符も二重引用符に変更したことに注意してください。ここで必要なエスケープは単一引用符では許可されないため、これが必要でした ( http://ss64.com/ps/syntax-esc.html )。

アーロンの答えはうまくいくはずです。そうでない場合は、setupFilePath-f1"d:\space here\file.ext"が期待どおりに解釈されていないと思います。

意見アラート私が彼の答えに追加する唯一のことは、引数のパス内で変数を使用できるようにするために、二重引用符とバックティックを使用することを提案することです-f1:

Start-Process -FilePath $setupFilePath -ArgumentList '-a','-s',"-f1`"$pathToVCCS`"" |
Wait-Process

この方法では、長い行の途中にハードコードされた絶対パスがありません。

于 2015-02-07T03:59:30.483 に答える
2

PowerShell v3 では、次のように動作します。

& $setupFilePath -a -s -f1:"d:\some directory\with blanks in a path\fileVCCS.iss"

PSCX echoargs コマンドを使用すると、次のようになります。

25> echoargs.exe -a -s -f1"d:\some directory\with blanks in a path\fileVCCS.iss"
Arg 0 is <-a>
Arg 1 is <-s>
Arg 2 is <-f1d:\some directory\with blanks in a path\fileVCCS.iss>

Command line:
"C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe"  -a -s "-f1d:\some directory\with blanks in a path\fileVCCS.iss"

V2 を使用する場合 - 最後の二重引用符にバッククォートが追加されていることに注意してください。

PS> echoargs.exe -a -s -f1"d:\some directory\with blanks in a path\fileVCCS.iss`"
Arg 0 is <-a>
Arg 1 is <-s>
Arg 2 is <-f1d:\some directory\with blanks in a path\fileVCCS.iss>

Command line:
"C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe"  -a -s -f1"d:\some directory\with blanks in a path\fileVCCS.iss"
于 2013-07-10T01:13:07.683 に答える