473,769 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Readline hangs in process.Standar dOutput

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(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
Nov 15 '05 #1
1 8880

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
|
|
|

Nov 15 '05 #2

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

Similar topics

0
2041
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 be really useful is to be able to use the server as a sort of cmd prompt remote control. I use the same sort of code below I can write a cmd to the popen2 cmd but when reading them it reads but then hangs on the readline there isn't a end of...
0
1023
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 impersonating as the admin user and providing the login credentials through the process.StartInfo.UserName and process.StartInfo.Password attributes. Process process = new Process(); process.StartInfo.FileName = @"C:\Program Files\Common
1
1686
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 redirect the output to a msgbox and display it on the screen. However, when I put this as an asp.net web page, the process just hangs. I am able to do other processes from the same web page and get the results, but when I try to launch this one...
0
7228
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 1.1 framework, but discovered that when I used Process.Start() the user's credentials were not impersonated, it just kept using the asp.net's user, so I switched the webservice over to 2.0 as Diagnostics.Process.StartInfo now has username,...
11
13459
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 executable will exhibit this problem; it is not specific to whoami.exe. This is with .NET 2.0, of course (1.1 does not support running a process as a different user). This appears to be a bug. Can anyone comment? <%@ WebService Language="C#"...
0
2245
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 trap and output to a client. Having read a bit of literature about this, i realise that it is necessary to start a new thread to report on the progress of the process using StandardOutput. However, the first attempt to read from this stream causes...
6
12850
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 doesn't return) until the process exits??? Any help is highly appreciated! The code is like this: Process myProcess = new Process(); myProcess.StartInfo.FileName = Application.StartupPath + "\\myCmdLine.exe";
2
6880
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 program. That works for 95 %, but the other 5 % it doesn't. It seems to me that the started process just hangs, and therefor my program hangs, too (p.WaitForExit()). I researched that this only happens when the output of the program is longer than...
5
3304
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 have to develop a webservice which is run on the server. The
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.