473,383 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Readline hangs in process.StandardOutput

JC
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(string cmds, ArrayList files)

{

try

{

StreamReader sr = VSCmd.StandardOutput; // VSCmd is the Process
object running cmd.

string s;

string t = "";
foreach(string file in files)

{

stWriter.WriteLine("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.MessageBox.Show(t);

return true;

}

catch (Exception e)

{

System.Diagnostics.Debug.WriteLine("Error in
CVSCmdPrompt.RunCOmmands: " + 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
Nov 15 '05 #1
1 8787

Hi JC,

Thanks for posting in this group.
To redirect the StandardOutput you should first set
ProcessStartInfo.RedirectStandardInput to true, then set
ProcessStartInfo.UseShellExecute to false.
Do like this:
try
{
Process VSCmd=new Process();
VSCmd.StartInfo=new ProcessStartInfo(@"C:\Program Files\Microsoft Visual
Studio\VC98\Bin\dumpbin.exe");
VSCmd.StartInfo.Arguments=@"C:\WINDOWS\system32\no tepad.exe";
VSCmd.StartInfo.RedirectStandardOutput=true;
VSCmd.StartInfo.UseShellExecute=false;

VSCmd.Start();

StreamReader sr = VSCmd.StandardOutput; // 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.MessageBox.Show(t);
}
catch (Exception ex)
{
MessageBox.Show("Error in CVSCmdPrompt.RunCOmmands: " + 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.StandardOutput
| 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.public.dotnet.languages.csharp
| NNTP-Posting-Host: tide106.microsoft.com 207.46.228.31
| Path:
cpmsftngxa08.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP09.
phx.gbl
| Xref: cpmsftngxa08.phx.gbl microsoft.public.dotnet.languages.csharp:198478
| X-Tomcat-NG: microsoft.public.dotnet.languages.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(string cmds, ArrayList files)
|
| {
|
| try
|
| {
|
| StreamReader sr = VSCmd.StandardOutput; // VSCmd is the
Process
| object running cmd.
|
| string s;
|
| string t = "";
|
|
| foreach(string file in files)
|
| {
|
| stWriter.WriteLine("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.MessageBox.Show(t);
|
| return true;
|
| }
|
| catch (Exception e)
|
| {
|
| System.Diagnostics.Debug.WriteLine("Error in
| CVSCmdPrompt.RunCOmmands: " + 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
|
|
|

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Guy | last post by:
Ok this is might take some exsplaining as this is just example code, I have a telnet server which I've created, its ment to be a a process queue control thing. One of the things I think that would...
0
by: Abhi | last post by:
Hi- I'm trying to execute the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\50\bin\OWSADM.EXE programmatically from a shell using the process.Start() method. I'm also...
1
by: Scott | last post by:
I am trying to write an asp.net web page that will spawn a third party .exe file and return the results back to my asp page. I am able to write a vb.net program that will do this just fine. I...
0
by: Paul | last post by:
Hi, I'm trying to kick off the iiscnfg.vbs from a webservice to export a website's config to an xml file (And eventually populate other servers with the config). I initially tried this using the...
11
by: Kirk | last post by:
The following C# web service works fine until you uncomment the lines setting UserName and Password. Then the process starts as the specified user, but hangs in a suspended state. In fact, any...
0
by: smimon | last post by:
Hi I'm trying to run a DTS package from a ASP.NET web page using System.Diagnostics.Process. This DTS takes up to 10 minutes to complete, during which, output is generated which i would like to...
6
by: Ole | last post by:
Hi, I'm running a command line process from my C# application trying to catch the output messages from the process into a textbox in my windows form. But the text doesn't update (the ReadLine...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
5
by: Saya | last post by:
Hi Folks, I have now spend app. 3 days to get the below scenario to work, but can not get there! ..Net version = 2.0.50727 Windows version = Microsoft Windows = Windows Server 2003 Now I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.