Proccess oluştur. Sonra döngü ile stdout'u TextBox'a aktar.Merhaba;
Py kodlarının çıktısını anlık olarak C# Windows forms uygulamasının textbox'ına aktarmanın bir yolu var mı?
Denedim.Proccess oluştur. Sonra döngü ile stdout'u TextBox'a aktar.
StreamReader outputReader = null;
StreamReader errorReader = null;
try
{
btnStart.Enabled = false;
//Create Process Start information
ProcessStartInfo pi =
new ProcessStartInfo("py", arg);
pi.ErrorDialog = false;
pi.UseShellExecute = false;
pi.RedirectStandardError = true;
pi.RedirectStandardInput = true;
pi.RedirectStandardOutput = true;
//Execute the process
Process p = new Process();
p.StartInfo = pi;
bool ps = p.Start();
if (ps)
{
//Get the output stream
outputReader = p.StandardOutput;
errorReader = p.StandardError;
p.WaitForExit();
//Display the result
string displayText = "Output" + Environment.NewLine + "==============" + Environment.NewLine;
displayText += outputReader.ReadToEnd();
displayText += Environment.NewLine + "Error" + Environment.NewLine + "==============" +
Environment.NewLine;
displayText += errorReader.ReadToEnd();
txtResult.Text = displayText;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if(outputReader != null)
{
outputReader.Close();
}
if(errorReader != null)
{
errorReader.Close();
}
btnStart.Enabled = true;
}
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.