Process.ExitCode returns InvalidOperationException when starting process with RedirectStandardInput

  • Thread starter Thread starter SMichal
  • Start date Start date
S

SMichal

Hi, I'm starting my process and cannt get ExitCode...It generates
exception - >InvalidOperationException <-



StringBuilder args1 = new StringBuilder();

args1.Append("-n" + localhost + " -u" + userName + " -p" + password + " ");


Process myProcess = new Process();

myProcess.StartInfo.FileName = cdHome + "Direct.exe";

myProcess.StartInfo.Arguments = args1.ToString();

myProcess.StartInfo.UseShellExecute = false;

myProcess.StartInfo.RedirectStandardInput = true;

myProcess.StartInfo.RedirectStandardError = true;

myProcess.StartInfo.RedirectStandardOutput = true;

myProcess.Start();

// input

StreamWriter myStreamWriter = myProcess.StandardInput;

string[] procedData = File.ReadAllLines(prozessFile);

for (int i = 0; i < procedData.Length; i++)

{

myStreamWriter.WriteLine(procedData);

}

myStreamWriter.Close();

//File.WriteAllText(temp + "StdInLog.txt", procedData.ToString()); // tohle
frenzel jeste nema

// output - mam vystup z aplikace

string output = myProcess.StandardOutput.ReadToEnd();

File.WriteAllText(temp + "StdOutLog.txt", output);

// error output z aplikace

string outputErr = myProcess.StandardError.ReadToEnd();

File.WriteAllText(temp + "StdErrorLog.txt", outputErr);

// Wait for the sort process to write the sorted text lines.

myProcess.WaitForExit();

int code = myProcess.ExitCode; // GENERATES EXCEPTION

myProcess.Close();



Could me somebody help ?
 
Back
Top