この場合、「/ c」の後ろにスペースがない可能性があります。コマンドウィンドウに表示するためのよう
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
、代わりに、あなたはおそらく、あなたのprocessStartInfo
インスタンスのArguments
プロパティを検査したほうが良いでしょう。コマンドラインを使用すると、投稿の詳細を考慮に入れると
EDIT
、私はこれがあなたの問題が何であるかであると考えています。
If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters:
If all of the following conditions are met, then quote characters on the command line are preserved:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters, where special is one of: &<>()@^|
- there are one or more whitespace characters between the the two quote characters
- the string between the two quote characters is the name of an executable file.
あなたは/ cを使用しているので、引用符と特殊文字の問題は解決されています。 commandString
全体を複数の引用符で囲みます。
例えば、この単純な例(手動でのコースTEMP.TXT作成)を取る:/c "C:\WINDOWS\Notepad.exe" "C:\temp.txt"
、これはC」ため失敗します:実行するコマンドラインはなり
string commandString = @"""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""";
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
を\ TEMP.TXT "は実行可能ファイルではありません。
string commandString = @"""""C:\WINDOWS\Notepad.exe"" ""C:\temp.txt""""";
var processStartInfo = new ProcessStartInfo("cmd", "/c " + commandString);
のコマンドラインに結果として得られる:/c ""C:\WINDOWS\Notepad.exe" "C:\temp.txt""
、最終的にあなたのテストファイルをメモ帳を開いて、あなたが引用符の最後のセットで全体を包む場合
は、あなたが意図した結果が表示されるはずです。
これは実際問題ですが、残念ながらまだ動作していません。 – sooprise
コマンドとargを使用していることについて、より多くの情報を与えることができますか?コマンドラインのテストとアプリケーションのテストで異なるコマンドを実行した場合のベースディレクトリに問題がありますか? –
@sooprise:エスケープ文字に問題がある場合は、 '' C:\\ sumptin ''の代わりに '@" C:\ sumptin "のように文字列を' @ 'で始めることを検討してください。 –