Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process
to run a C application and redirecting its standard output so I can read it
with StreamReader.Re adToEnd. It's only reading the 1st 5 lines or so when
there is about 30 lines of data.
I also tried using the Process.BeginOu tputReadlin and a
DataReceivedEvn tHandler to gather output but I also only get about 5 lines of
the data.
There seems to be a buffer size issue. Can someone tell me how can I
resolve this problem. Thank you.
--
Thanks. 11 9241
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process
to run a C application and redirecting its standard output so I can read it
with StreamReader.Re adToEnd. It's only reading the 1st 5 lines or so when
there is about 30 lines of data.
I also tried using the Process.BeginOu tputReadlin and a
DataReceivedEvn tHandler to gather output but I also only get about 5 lines of
the data.
There seems to be a buffer size issue. Can someone tell me how can I
resolve this problem. Thank you.
It should work fine. Do you know if your C application is actually
finishing? You should read from standard error as well as standard out
- otherwise if it's trying to write to standard error, it may be
blocking.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Here is my code on first try to read the standard output. In the debug mode
I can see some lines of the data are read in but the process never has a
exited status. I even took away the time out value and it just hangs and
sits there and I can see the stream buffer hits a limit and hangs.
listFiles.WaitF orExit();
Is there a way to read all my data in without a buffer limitation? Thank you.
public static int GetNisFile(Syst em.Diagnostics. ProcessStartInf o psi,
ref DataTable dtAccounts,
ref ToolStripStatus Label slMain, ref StatusStrip ssMain, string
userOrGroup)
{
string accountFile="", output="";
int numOfAccounts = 0;
System.IO.Strea mReader fileOutput = null, myOutput = null;
System.Diagnost ics.Process listFiles;
try
{
listFiles = System.Diagnost ics.Process.Sta rt(psi);
if (listFiles != null)
{
myOutput = listFiles.Stand ardError;
fileOutput = listFiles.Stand ardOutput;
listFiles.WaitF orExit(30000);
if (listFiles.HasE xited)
{
// Read and display lines from the file until the end of
// the file is reached.
accountFile = fileOutput.Read ToEnd();
output = myOutput.ReadTo End();
if (accountFile != null && accountFile != "")
numOfAccounts =
CPAUnix.ParseAn dInsertAccounts (accountFile,
ref dtAccounts, ref slMain, ref ssMain, userOrGroup);
}
else
MessageBox.Show ("Time out retrieving NIS" + userOrGroup +
"accounts." ,
"PowerADvantage ");
}
else
MessageBox.Show ("Error starting process to read file.",
"PowerADvantage ");
return numOfAccounts;
}
catch (Win32Exception wex)
{
MessageBox.Show (wex.Message, "PowerADvantage ");
return numOfAccounts;
}
}
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process
to run a C application and redirecting its standard output so I can read it
with StreamReader.Re adToEnd. It's only reading the 1st 5 lines or so when
there is about 30 lines of data.
I also tried using the Process.BeginOu tputReadlin and a
DataReceivedEvn tHandler to gather output but I also only get about 5 lines of
the data.
There seems to be a buffer size issue. Can someone tell me how can I
resolve this problem. Thank you.
It should work fine. Do you know if your C application is actually
finishing? You should read from standard error as well as standard out
- otherwise if it's trying to write to standard error, it may be
blocking.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Here is my code using BeginOutputRead Line. This code doesn't have the time
out issue but it only returns 5 lines of data.
static System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
static void proc_OutputData Received(object sender, DataReceivedEve ntArgs e)
{
sb.Append(e.Dat a);
}
public static int GetNisFile(Syst em.Diagnostics. ProcessStartInf o psi,
ref DataTable dtAccounts,
ref ToolStripStatus Label slMain, ref StatusStrip ssMain, string
userOrGroup)
{
string accountFile = "", output = "", line = "", theResult="";
int numOfAccounts = 0;
System.IO.Strea mReader fileOutput = null, myOutput = null;
System.Diagnost ics.Process listFiles = new Process();
listFiles.Start Info = psi;
try
{
String inputText;
int numInputLines = 0;
listFiles.Outpu tDataReceived += new
DataReceivedEve ntHandler(proc_ OutputDataRecei ved);
//listFiles = System.Diagnost ics.Process.Sta rt(psi);
// Use a stream writer to synchronously write the sort input.
listFiles.Start ();
//StreamReader nisReader = listFiles.Stand ardOutput;
listFiles.Begin OutputReadLine( );
listFiles.WaitF orExit();
theResult = sb.ToString();
listFiles.Cance lOutputRead();
listFiles.Kill( );
return numOfAccounts;
}
catch (Win32Exception wex)
{
MessageBox.Show (wex.Message, "PowerADvantage ");
return numOfAccounts;
}
}
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process
to run a C application and redirecting its standard output so I can read it
with StreamReader.Re adToEnd. It's only reading the 1st 5 lines or so when
there is about 30 lines of data.
I also tried using the Process.BeginOu tputReadlin and a
DataReceivedEvn tHandler to gather output but I also only get about 5 lines of
the data.
There seems to be a buffer size issue. Can someone tell me how can I
resolve this problem. Thank you.
It should work fine. Do you know if your C application is actually
finishing? You should read from standard error as well as standard out
- otherwise if it's trying to write to standard error, it may be
blocking.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Here is my code on first try to read the standard output. In the debug mode
I can see some lines of the data are read in but the process never has a
exited status. I even took away the time out value and it just hangs and
sits there and I can see the stream buffer hits a limit and hangs.
listFiles.WaitF orExit();
Is there a way to read all my data in without a buffer limitation? Thank you.
You need to read the data in a different thread, basically. I don't
have the time to write the code right now, but if you have one thread
reading the stdout and one reading stderr, you shouldn't see this
problem.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Thanks Jon, I did read the article on the parent, child process deadlock
issue. I modified my code to use sync. read for the stderr and async. read
for the stadout. But, I'm still getting just a few lines of my stdout. I
ran the C application again and it gets over 100 lines of data. Thank you.
static System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
static void proc_OutputData Received(object sender, DataReceivedEve ntArgs e)
{
sb.Append(e.Dat a);
}
public static int GetNisFile(Syst em.Diagnostics. ProcessStartInf o psi, string
parm,
ref DataTable dtAccounts,
ref ToolStripStatus Label slMain, ref StatusStrip ssMain, string
userOrGroup)
{
string accountFile = "", output = "", line = "", theResult="";
int numOfAccounts = 0;
String inputText;
int numInputLines = 0;
System.IO.Strea mReader fileOutput = null, myOutput = null;
System.Diagnost ics.Process listFiles = new Process();
//listFiles.Start Info = psi;
try
{
listFiles.Outpu tDataReceived += new
DataReceivedEve ntHandler(proc_ OutputDataRecei ved);
listFiles.Start Info = new ProcessStartInf o(Application.S tartupPath +
"\\ypcat.ex e", parm);
listFiles.Start Info.UseShellEx ecute = false;
listFiles.Start Info.RedirectSt andardOutput = true;
listFiles.Start Info.RedirectSt andardError = true;
//listFiles = System.Diagnost ics.Process.Sta rt(psi);
// Use a stream writer to synchronously write the sort input.
if (listFiles.Star t())
{
//StreamReader nisReader = listFiles.Stand ardOutput;
listFiles.Begin OutputReadLine( );
string error = listFiles.Stand ardError.ReadTo End();
listFiles.WaitF orExit();
if(listFiles.Ha sExited)
theResult = sb.ToString();
listFiles.Cance lOutputRead();
listFiles.Close ();
}
return numOfAccounts;
}
catch (Win32Exception wex)
{
MessageBox.Show (wex.Message, "PowerADvantage ");
return numOfAccounts;
}
}
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Here is my code on first try to read the standard output. In the debug mode
I can see some lines of the data are read in but the process never has a
exited status. I even took away the time out value and it just hangs and
sits there and I can see the stream buffer hits a limit and hangs.
listFiles.WaitF orExit();
Is there a way to read all my data in without a buffer limitation? Thank you.
You need to read the data in a different thread, basically. I don't
have the time to write the code right now, but if you have one thread
reading the stdout and one reading stderr, you shouldn't see this
problem.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On Aug 6, 8:58 am, Pucca <Pu...@discussi ons.microsoft.c omwrote:
Thanks Jon, I did read the article on the parent, child process deadlock
issue. I modified my code to use sync. read for the stderr and async. read
for the stadout. But, I'm still getting just a few lines of my stdout.
Without full code to run ourselves, it's pretty tricky to diagnose
this.
I suggest you first swap out the original process for a "dummy"
process written in C# which just writes 100 lines of output to both
stdout and stderror - then come up with a short but complete program
in C# which shows the problem occurring. That way we can all look at
the same issue.
Jon
Ok, I will do that. Sounds like a good test. Also, I forgot to mention that
I'm running on Windows 2000 server. Would this be the problem?
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
On Aug 6, 8:58 am, Pucca <Pu...@discussi ons.microsoft.c omwrote:
Thanks Jon, I did read the article on the parent, child process deadlock
issue. I modified my code to use sync. read for the stderr and async. read
for the stadout. But, I'm still getting just a few lines of my stdout.
Without full code to run ourselves, it's pretty tricky to diagnose
this.
I suggest you first swap out the original process for a "dummy"
process written in C# which just writes 100 lines of output to both
stdout and stderror - then come up with a short but complete program
in C# which shows the problem occurring. That way we can all look at
the same issue.
Jon
Pucca <Pu***@discussi ons.microsoft.c omwrote:
Ok, I will do that. Sounds like a good test. Also, I forgot to mention that
I'm running on Windows 2000 server. Would this be the problem?
Shouldn't be, no.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
I created 2 applications as you said and it works! So, I use the new C#
application and instead of calling the dummy program I called my C
application and display the output to a textbox and that works too! Now, I'm
really confused about why it doesn't work in my program.
--
Thanks.
"Jon Skeet [C# MVP]" wrote:
On Aug 6, 8:58 am, Pucca <Pu...@discussi ons.microsoft.c omwrote:
Thanks Jon, I did read the article on the parent, child process deadlock
issue. I modified my code to use sync. read for the stderr and async. read
for the stadout. But, I'm still getting just a few lines of my stdout.
Without full code to run ourselves, it's pretty tricky to diagnose
this.
I suggest you first swap out the original process for a "dummy"
process written in C# which just writes 100 lines of output to both
stdout and stderror - then come up with a short but complete program
in C# which shows the problem occurring. That way we can all look at
the same issue.
Jon
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: codefixer |
last post by:
Hi,
I was wondering what factors will influence the maximum buffer sizes
for source and destination for memcpy(). Is their any limit to the
sizeof the buffer(hardware restricting it ?) OR any other limitations
like the compiler being used ?
Your thoughts are appreciated.
Thanks.
|
by: BMax |
last post by:
Hello
I want to create a byte and use it as a buffer, then access it with a
binaryreader or streamreader.
what is important is to be able to read different variables form that, like
readint16, readbytes(),readint32.... . so if there is a method to read byte
arrays that would also help.
(i couldn' use convert class )
is that possible? if yes how?
|
by: ad |
last post by:
Have there any limitation about the size of the file uploaded by FileUpload
control?
|
by: chenatcr |
last post by:
Hello,
I added a serial-USB converter to my laptop, it appear as USB serial
port COM4, and I wrote an application to read 78k data from this port.
In my VC++ express code, I defined ReadBufferSize = 78k, and
ReceivedBytesThreashold = 78k so that I can get the whole data with
one ReadExisting() method when DataReceived event fires.
|
by: aki |
last post by:
Hi all,
i am writing codes for implementing network protocols.
i have written a method which is receiving a packet from network.
i have assumed that the packet i will receive will be of type char*.
i need to test my method and
for that i want to create a network buffer which will contain a
packet of format as->
example of Configuration req packet
uint8_t code;
| |
by: Jack |
last post by:
Hi,
I want to read a string a chars from a stream, and put it into a
string.
At the moment, I'm creating a buffer of a fixed size, and reading the
stream of text into it. It works, but I have to create a buffer of a
pre-defined length: (ConstBufferByteSize=10000000). How can I read a
stream into a buffer or string without knowing the number of chars the
stream will contain?
|
by: =?Utf-8?B?UHVjY2E=?= |
last post by:
-- Hi I'm using vs2005, .net 2 for windows application. The application I
started using System.Diagnostics.Process is having a
"listFiles.StandardOutput" buffer size problem. I was wondering where and
how can I adjust the buffer size problem. I don't want to be limited to a
set buffer size, is that possible? thank you.
public static int GetNisFile(System.Diagnostics.ProcessStartInfo psi,
ref DataTable dtAccounts,
ref...
|
by: lapucca |
last post by:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process
to run a C application and redirecting its standard output so I can read it
with StreamReader.ReadToEnd. It's only reading the 1st 5 lines or so when
there is about 100 lines of data.
I also tried using the Process.BeginOutputReadlin and a
DataReceivedEvntHandler to gather output but I also only get about 5 lines of
the data.
There seems to be a buffer...
|
by: bennett |
last post by:
I have written the following function
Public Function ReadFile(ByVal FileName As String) As String
Dim objReader As StreamReader = Nothing
Dim objData As New StringBuilder
Dim strReturn As String = ""
Try
objReader = New StreamReader(FileName, Encoding.Default, True, 512)
objData.Append(objReader.ReadToEnd)
strReturn =...
|
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...
|
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,...
| |
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |