投稿

10月, 2017の投稿を表示しています

FormApplicationでのPsExecのStandardOutput

C#からPsExecをコンソールアプリケーションとして呼び出す場合、Processクラスを利用するが、利用方法によってはStandardOutputが全て取得できない場合があった 現象としては C#のFormApplicationとしてプロジェクトを作成して ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "hoge¥¥PsExec.exe"; info.Arguments = "¥¥¥¥127.0.0.1 cmd /c ¥"type hoge¥¥¥¥a.txt"; 略 string output = info.StandartOutput.ReadToEnd(); とした場合、outputにはa.txtに含まれる長さによっては途中までしか読み取れない 解決方法としては、 info.FileName = "cmd.exe"; として、一旦コマンドプロンプトから実行するものとして指定し info.Arguments = "hoge¥¥¥¥PsExec.exe ¥¥¥¥127.0.0.1 /cmd /c ¥"type hoge¥¥¥¥a.txt"; とすると、正常に読み取られる FormApplicationではなく、ConsoleApplicatioとしてプロジェクトを作成した場合は、この限りではない