Hide process window...

I am trying to create a process to execute command line command, and redirect the result to the process stream reader...
The problem is I cannot hide the command (dos) window... even I setup WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
Here is my code ...
==========================================
Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "p4";
myProcess.StartInfo.Arguments = @"-p testServer:1234 -c test_client files C:\test.xml";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit();
string output = myProcess.StandardOutput.ReadToEnd();
==========================================
Could you help me to hide the command window?
Thank you!
billcchAsked:
Who is Participating?
 
sumixCommented:
Add

     myProcess.StartInfo.CreateNoWindow = true;

 before myProcess.Start()
0
 
sumixCommented:

Also, note that is a good practice to read the output buffer before calling WaitForExit method, as if the process writes out to many data, it can cause a deadlock.
See
http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput(VS.80).aspx  or,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessStartInfoClassRedirectStandardOutputTopic.asp 
 ( for .Net framework 1.1)
0
 
Expert1701Commented:
Process.WaitForExit does not need to be called at all, in this example, as the Process.StandardOutput.ReadToEnd method will not return until the standard output stream has closed (i.e. the process has exited).
0
 
billcchAuthor Commented:
Thank you so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.