OVH Cloud OVH Cloud

Masquer l'affichage de la console

2 réponses
Avatar
Sylfelin
Soit le code ci-dessous pour lancer une application console.
Margré un process.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden la fenêtre console
apparait à l'écran.

Comment faire pour la masquer complétement ?

Merci

System.Diagnostics.Process process;
string output;

process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false; // On désactive le
shell
process.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden &
System.Diagnostics.ProcessWindowStyle.Minimized;
process.StartInfo.RedirectStandardOutput = true; //On redirige la
sortie standard
process.StartInfo.FileName = "consapp.exe"; //On définit la
commande
process.StartInfo.Arguments = "-V";
process.Start();
output = process.StandardOutput.ReadToEnd(); //Lecture de la
sortie de la commande
process.WaitForExit();
process.Close();

--
---
Sylfelin

2 réponses

Avatar
Patrick Philippot
Bonjour,

Le mieux est peut-être de compiler l'application comme application Windows
(/t:winexe) et de ne pas créer de fenêtre. Rien n'apparaîtra à l'écran.

--
Patrick Philippot - Microsoft MVP
MainSoft Consulting Services
www.mainsoft.fr


"Sylfelin" wrote in message
news:
Soit le code ci-dessous pour lancer une application console.
Margré un process.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden la fenêtre console apparait à
l'écran.

Comment faire pour la masquer complétement ?

Merci

System.Diagnostics.Process process;
string output;

process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false; // On désactive le shell
process.StartInfo.WindowStyle > System.Diagnostics.ProcessWindowStyle.Hidden &
System.Diagnostics.ProcessWindowStyle.Minimized;
process.StartInfo.RedirectStandardOutput = true; //On redirige la
sortie standard
process.StartInfo.FileName = "consapp.exe"; //On définit la commande
process.StartInfo.Arguments = "-V";
process.Start();
output = process.StandardOutput.ReadToEnd(); //Lecture de la sortie
de la commande
process.WaitForExit();
process.Close();

--
---
Sylfelin




Avatar
Sylfelin
Patrick Philippot a exprimé avec précision :
Bonjour,

Le mieux est peut-être de compiler l'application comme application Windows
(/t:winexe) et de ne pas créer de fenêtre. Rien n'apparaîtra à l'écran.




Je n'ai pas le source.

Mais j'ai trouvé je n'avait pas redirigé la sortie standard

process.StartInfo.RedirectStandardError = true;

--
---
Sylfelin