こんにちは、PowerShellの実行に問題があります。例:
cmd = EvalInsert(
"\[$imageFile = "test"]\");
rp1 = RunProgram(Executable("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ),
Options(Eval(cmd)),
ReadFunction("text")
);私が使用したい実際のコマンドはもっと複雑ですが、スピーチマークでも同じ問題があります。 ログにrp1を出力すると、次のようになります。
"test : The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ $imageFile = test
+ ~~~~
+ CategoryInfo : ObjectNotFound: (test:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
" これは、ラインがスピーチマークなしで実行されたことを意味します。
スピーチマークが正しく実行されていることを確認するにはどうすればよいですか?
これについて助けてくれてありがとう。
Windows のコマンド ライン、引用符、エスケープ、そしてなぜそれが難しいのかについての素晴らしい説明に偶然出会いました。
http://www.windowsinspired.com/the-correct-way-to-quote-command-line-arguments/
http://www.windowsinspired.com/ Understanding-the-command-line-string-and-arguments-received-by-a-windows-program/
http://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/
過度に単純化されています: コマンド ライン上の複数の引数は、スペースで区切られます。各引用符は、引数を区切るためにスペースを使用するかどうかを切り替えます。\\ はリテラル \ であり、\" はリテラル " です。スペースをオフにすると、2 つの隣接する引用符はリテラル " になりますが、スペースは、使用するパーサーのバリエーションに応じてオンまたはオフに切り替わる場合があります。
2025年1月20日更新: リンクが古くなったため、Web アーカイブ バージョン:
http://web.archive.org/web/20220629215303/http://windowsinspired.com/the-correct-way-to-quote-command-line-arguments/
https://web.archive.org/web/20220629212707/https://www.windowsinspired.com/ Understanding-the-command-line-string-and-arguments-received-by-a-windows-program/
https://web.archive.org/web/20220629212422/https://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/
コマンドライン引数には、PowerShellコマンドライン解析を機能させるために、いくつかの追加の引用符とエスケープが必要です。 (PowerShellを使用するのは2回目ですが、何かを見落としている可能性があります...) (また、このWebページの構文の色付けは、角括弧の引用符のエスケープでは間違っています。)
command = "\["$imagefile = \"test\";echo $imagefile"]\";
Write( "\!nthe command is:", command ); // write shows it in the log without extra escapes
result = RunProgram(
executable( "powershell.exe" ), //
options( command ), //
readfunction( "text" )//
);
Show( result );
コマンドは次のとおりです: "$ imagefile = \" test \ "; echo $ imagefile"
結果="テスト
";
これは、CMDウィンドウで行った2回の試行のスクリーンキャプチャです。
powershell output in a CMD windowpowershell output in a CMD windowpowershell output in a CMD windowCMDウィンドウでのPowerShell出力
外側の引用符は、PowerShellに単一のオプションを表示させます。外側の引用符は、PowerShellがテキストを取得する前にCMDによって削除されます。 元の例では、PowerShellが受け取った3つのアイテム($ imagefile、=、test)があり、テストの前後の外側の引用符はCMDによって削除されました。 引数に引用符またはスペースがある場合は、外側の引用符が必要です。