以下のコードでは、DevCon.exeを使用して何かをキャプチャし、ファイルに書き込みます。必要に応じてこのファイルを解析します。
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C devcon.exe find = port *monitor* >> monitor_Details.txt";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.Verb = "runas";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
StreamReader sr = p.StandardOutput;
string log = sr.ReadToEnd();
StreamWriter sw = p.StandardInput;
sw.WriteLine("hi.txt");
p.Close();
ここでは、txtファイルが常に空白になっているのがわかります。テキストファイルには何も書き込まれません。何か問題でもありますか?に割り当てられる変数ログも確認しました
sr.ReadToEnd()
それでも、ログは常に空白です。
Plは、シェルコマンドが実行されない理由を示しています。