Bonjour à tous,
J'ai un process dont le code C est le suivant :
Je cherche à récupérer en temps réel, la sortie standard de ce programme dans un autre programme C#.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 int main() { char a; printf("coucou\n"); printf("coucou2\n"); printf("Entrer un caractere :"); scanf("%c", &a); printf("FIN\n"); return 0; }
Pour cela j'utilise :
Le problème est que je ne reçois rien du tout sur le flux de sortie standard du process... Tout cela est à cause du scanf du programme enfant. Si je le supprime, alors tout marche bien.
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 using (var process = new FixedProcess()) { process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.FileName = fileName; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = BASE_PATH; process.OutputDataReceived += (sender, args) => { if (args.Data != null) { MessageBox.Show("ici " + args.Data); Console.WriteLine("Info : " + args.Data); } }; process.Start(); process.BeginOutputReadLine(); if (process.WaitForExit(timeout)) { exitCode = process.ExitCode; } else { process.Kill(); throw new TimeoutException("Process wait timeout expired"); } }
Mais ce que je veux, c'est récupérer :
Comment faut-il faire ? Il semble que OutputDataReceived soit déclenchée uniquement quand la ligne termine par \r\n mais de tout façon je n'ai rien du tout...coucou
coucou2
Entrer un caractere :
Merci à vous![]()
Partager