Hi JC,
Thanks for posting in this group.
To redirect the StandardOutput you should first set
ProcessStartInf o.RedirectStand ardInput to true, then set
ProcessStartInf o.UseShellExecu te to false.
Do like this:
try
{
Process VSCmd=new Process();
VSCmd.StartInfo =new ProcessStartInf o(@"C:\Program Files\Microsoft Visual
Studio\VC98\Bin \dumpbin.exe");
VSCmd.StartInfo .Arguments=@"C: \WINDOWS\system 32\notepad.exe" ;
VSCmd.StartInfo .RedirectStanda rdOutput=true;
VSCmd.StartInfo .UseShellExecut e=false;
VSCmd.Start();
StreamReader sr = VSCmd.StandardO utput; // VSCmd is the Process object
running cmd.
string s;
string t = "";
while ((s=sr.ReadLine ())!=null) // When Dumpbin runs once,it finishes
with a prompt; application will hang here waiting for a return.
t += s;
sr.Close();
System.Windows. Forms.MessageBo x.Show(t);
}
catch (Exception ex)
{
MessageBox.Show ("Error in CVSCmdPrompt.Ru nCOmmands: " + ex.Message);
}
It works well on my machine, hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "JC" <none>
| Subject: Readline hangs in process.Standar dOutput
| Date: Tue, 18 Nov 2003 15:48:40 -0800
| Lines: 70
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O8************ **@TK2MSFTNGP09 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: tide106.microso ft.com 207.46.228.31
| Path:
cpmsftngxa08.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP09 .
phx.gbl
| Xref: cpmsftngxa08.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1984 78
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| I'm trying to create a GUI wrapper for dumpbin, and so I'm using the
Process
| class to run the command-line application. The problem is that if I use
| Readline() to get the output from the commandline app, it will hang when
it
| comes to the command-prompt (there's no return to send it to readline).
| Here's the code:
|
| public bool RunCommands(str ing cmds, ArrayList files)
|
| {
|
| try
|
| {
|
| StreamReader sr = VSCmd.StandardO utput; // VSCmd is the
Process
| object running cmd.
|
| string s;
|
| string t = "";
|
|
| foreach(string file in files)
|
| {
|
| stWriter.WriteL ine("Dumpbin" + cmds + " " + file);
|
| while ((s=sr.ReadLine ())!=null) // When Dumpbin runs
once,
| it finishes with a prompt; application will hang here waiting for a
return.
|
| t += s;
|
| }
|
| System.Windows. Forms.MessageBo x.Show(t);
|
| return true;
|
| }
|
| catch (Exception e)
|
| {
|
| System.Diagnost ics.Debug.Write Line("Error in
| CVSCmdPrompt.Ru nCOmmands: " + e.ToString());
|
| return false;
|
| }
|
|
| }
|
|
|
| I want to loop through the files for various reasons, so I don't want to
| wait for the Process to shut down. Also, i've noticed that if i don't
| redirect the output to the process, Visual Studio sends it to the Output
| screen anyway! And it doesn't hang at the prompt. How does it do this?
Can I
| tap this?
|
|
|
| Thanks
|
| Josh
|
|
|