フォーラムを見た後、私はこのスニペットを書きました:
public string ExecuteCmd()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = this.m_command;
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
m_command
クラスのメンバーであり、コンストラクターで初期化されます。私のテストでは、net user
. コンパイラがこの時点に到達すると、次の例外が発生します。
StandardOut has not been redirected or the process hasn't started yet.
私の間違いはどこですか?