Bonjour,

Je voudrais rediriger la sortie standard actuelle (quand je fais un appel à Console.WriteLine() ) vers une textbox.
J'ai tenté ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Main()
{
Process currentProc = Process.GetCurrentProcess();
 
currentProc.StartInfo.RedirectStandardOutput = true;
currentProc.StartInfo.UseShellExecute = false; 
 
currentProc.OutputDataReceived += proc_DataReceived;
 
currentProc.BeginOutputReadLine();
 
Console.WriteLine("test de redirection console  vers textbox ?");
 
}
 
 void proc_DataReceived(object sender, DataReceivedEventArgs e)
 {
       textBoxMessageViewer.AppendText(e.Data);
 }


Mais j'ai comme erreur :

BeginOutputReadLine(); : StandardOut has not been redirected or the process hasn't started yet.
MSDN me dit d'assigner RedirectStandardOutput à true et UseShellExecute à false, c'est ce que j'ai fait.

Une idée ?

Merci pour votre aide.