Hallo liebe Community!
Ich habe in meiner Anwendung eine TextBox mit Multiline und ReadOnly. Meine Anwendung startet eine .cmd Datei und es öffnet sich ein Windows Konsolenfenster. Ist es möglich dieses auszublenden und die Ausgaben der Konsole in meine TextBox umzuleiten?
Danke schonmal!
Gruß Trekki
Habe noch ein bisschen weiter gesucht und foldendes zusammenprogrammiert ^^
myProcess.StartInfo = new ProcessStartInfo(tmpPath + "tmpplexec.cmd");
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
StreamReader mySr = myProcess.StandardOutput;
textBox1.Text = mySr.ReadToEnd();
myProcess.Start();
processId = myProcess.Id;
Ich bekomme aber jedesmal die Exception dass der StandardOutput nicht umgeleitet wäre.
Ich krieg ne Krise! X(
Hi,
so kann das ja schonmal gar nicht funktionieren, weil du den Stream ausliest, bevor du überhaupt das Programm startest. Da ist er natürlich leer.
Ansonsten in der MSDN:
Sie müssen UseShellExecute auf false festlegen, wenn Sie RedirectStandardOutput auf true festlegen möchten. Andernfalls löst das Lesen aus dem StandardOutput-Stream eine Ausnahme aus.
Grüße,
Big Al
Da man Spatzen nicht mit Kanonen jagt, sollte man auch nicht mit Computern auf Spatzenhirne losgehen.
Hier ein kleines Snippet von mir:
// prepare execution process
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe","/c \""+temporaryDirectory+"/Compiler.bat\"");
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
// execute
Process process = Process.Start(processStartInfo);
process.WaitForExit();
// read outputs
string stdOutput = process.StandardOutput.ReadToEnd();
string stdError = process.StandardError.ReadToEnd();
Gruß,
dN!3L
Vielen vielen Dank für eure Posts! Jetzt klappt es! ^^
Gruß Trekki