Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

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!
0
billcch
Asked:
billcch
  • 2
2 Solutions
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now