HI,
I am using Process.RedirectStandardOutput to read the output of a console process, quite successfully. (I am basically just doing "cmd.exe /c dir *.csproj /s /b" to list out all the .csproj files), however, instead of appending >textfile.txt to the end, I can use a StreamReader to read the data. This *seems* to be working successfully, but i was wondering what would happen if the application reading the data couldn't read (and process) it as fast as the process was outputting it?
Or does it (as I'm hoping) know that if its standard output redirected flag is true, then it needs to wait for each line that it outputs to be read before it can continue? I was hoping somebody could confirm this behaviour or tell me what it really is.
Thanks! 4 981
Beeeeeeeeeeeeves,
This can't happen. The process will output whatever it is going to do,
but when your StreamReader accesses it, it will be buffered until that line
is read from the buffer. You don't need to worry about the application
outputting information faster than you can process it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Beeeeeeeeeeeeves" <Be**************@discussions.microsoft.com> wrote in
message news:7E**********************************@microsof t.com... HI, I am using Process.RedirectStandardOutput to read the output of a console
process, quite successfully. (I am basically just doing "cmd.exe /c dir
*.csproj /s /b" to list out all the .csproj files), however, instead of
appending >textfile.txt to the end, I can use a StreamReader to read the
data. This *seems* to be working successfully, but i was wondering what
would happen if the application reading the data couldn't read (and process)
it as fast as the process was outputting it? Or does it (as I'm hoping) know that if its standard output redirected
flag is true, then it needs to wait for each line that it outputs to be read
before it can continue? I was hoping somebody could confirm this behaviour
or tell me what it really is. Thanks!
> This can't happen.
I thought so. The process will output whatever it is going to do, but when your StreamReader accesses it, it will be buffered until that line is read from the buffer.
OK, 'buffering' - so, I am imagining the StreamReader object storing up more and more lines in its memory waiting for me to retrieve them if the process is running faster than my program is reading it, so these lines will just be read as and when my program gets round to it.
You don't need to worry about the application outputting information faster than you can process it.
OK, I understand how it buffers it. But what if it happens the other way round? What if my application tries to read the information faster than the process can output it? Will it simply block until it *does* output something (and return null if it ends)?
What I'm currently doing is something like
using(Process p = new Process()) {
//.....starting the process...
String s;
while((s = p.StandardOutput.ReadLine()) != null) ProcessData(s);
//....I'm assuming the process has now finished its work and exited of its own accord.
//.. I don't need its return value or anything, but I do need to make sure it's allowed to finish of its own accord...
} //(end using)
and I'm *ASSUMING* that when the result of the assignment to the string s is null, then the fact that the process has no more data left to output means that it has finished.
IS this assumption valid, or should I use something different??? i.e. would anything else cause the result of StandardOutput.ReadLine() to be null apart from the process ending?
Beeeeeeeeeeeeves,
Yes, your application will block until it receives more input.
And your assumption is valid. The ReadLine method should return null if
there is nothing left to read from the stream.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Beeeeeeeeeeeeves" <Be**************@discussions.microsoft.com> wrote in
message news:D1**********************************@microsof t.com... This can't happen. I thought so.
The process will output whatever it is going to do, but when your StreamReader accesses it, it will be buffered until that
line is read from the buffer.
OK, 'buffering' - so, I am imagining the StreamReader object storing up
more and more lines in its memory waiting for me to retrieve them if the
process is running faster than my program is reading it, so these lines will
just be read as and when my program gets round to it.
You don't need to worry about the application outputting information faster than you can process it. OK, I understand how it buffers it. But what if it happens the other way
round? What if my application tries to read the information faster than the
process can output it? Will it simply block until it *does* output something
(and return null if it ends)? What I'm currently doing is something like using(Process p = new Process()) { //.....starting the process... String s; while((s = p.StandardOutput.ReadLine()) != null) ProcessData(s); //....I'm assuming the process has now finished its work and exited of its
own accord. //.. I don't need its return value or anything, but I do need to make sure
it's allowed to finish of its own accord... } //(end using)
and I'm *ASSUMING* that when the result of the assignment to the string s
is null, then the fact that the process has no more data left to output
means that it has finished. IS this assumption valid, or should I use something different??? i.e.
would anything else cause the result of StandardOutput.ReadLine() to be null
apart from the process ending?
right, excellent. thanks
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl... Beeeeeeeeeeeeves,
Yes, your application will block until it receives more input.
And your assumption is valid. The ReadLine method should return null
if there is nothing left to read from the stream.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Beeeeeeeeeeeeves" <Be**************@discussions.microsoft.com> wrote in message news:D1**********************************@microsof t.com... This can't happen. I thought so.
The process will output whatever it is going to do, but when your StreamReader accesses it, it will be buffered until that line is read from the buffer.
OK, 'buffering' - so, I am imagining the StreamReader object storing up more and more lines in its memory waiting for me to retrieve them if the process is running faster than my program is reading it, so these lines
will just be read as and when my program gets round to it.
You don't need to worry about the application outputting information faster than you can process it. OK, I understand how it buffers it. But what if it happens the other way round? What if my application tries to read the information faster than
the process can output it? Will it simply block until it *does* output
something (and return null if it ends)? What I'm currently doing is something like using(Process p = new Process()) { //.....starting the process... String s; while((s = p.StandardOutput.ReadLine()) != null) ProcessData(s); //....I'm assuming the process has now finished its work and exited of
its own accord. //.. I don't need its return value or anything, but I do need to make
sure it's allowed to finish of its own accord... } //(end using)
and I'm *ASSUMING* that when the result of the assignment to the string
s is null, then the fact that the process has no more data left to output means that it has finished. IS this assumption valid, or should I use something different??? i.e. would anything else cause the result of StandardOutput.ReadLine() to be
null apart from the process ending?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Williams |
last post by:
Hi,
I am trying to understand the performance implications of running a
number of separate ActiveXexe processes as opposed to a single
ActiveXexe with multiple threads on a Windows 2000 server....
|
by: AnalogKid |
last post by:
Short question:
What's the difference between SingleUse and MultiUse ?
Long question:
I've been writing some sample code to see how different Instancing
values and threading models work. I...
|
by: Thomas Schmid |
last post by:
Hi there,
I wrote a tcp server which listens on a port. When he gets a new
connection, he starts a new thread like this:
thread.start_new_thread(self.ConnectionHandler, (conn,))
where conn is...
|
by: Markus Breuer |
last post by:
I have a question about oracle commit and transactions. Following scenario:
Process A performs a single sql-INSERT into a table and commits the
transaction. Then he informs process B (ipc) to...
|
by: Mark Yudkin |
last post by:
The documentation is unclear (at least to me) on the permissibility of
accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003,
with separate transactions scope, from separate...
|
by: Stephen Barrett |
last post by:
After reading through the many many many posts on threading, I still don't
quite understand how to accomplish a task.
Here is an overview of the app I am coding. I am sorry if it is a little...
|
by: Jeremy |
last post by:
I have a core VB service that monitors a database, and based on data in the
records will execute code to send email notifications.
Problem:
I don't want my main program code to halt and wait for...
|
by: Abubakar |
last post by:
Hi,
in my application, different threads send notifications to GUI thread
through sendmessage api. They have special integer numbers inside the wParam
arg of sendmessage which the gui thread uses...
|
by: Carl J. Van Arsdall |
last post by:
Alright, based a on discussion on this mailing list, I've started to
wonder, why use threads vs processes. So, If I have a system that has a
large area of shared memory, which would be better? ...
|
by: Carl Johansson |
last post by:
If a multithreaded .NET application is executed on a computer with a
multicore processor. Will the application automatically run the threads on
different processor cores?
Regards Carl Johansson
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |