473,397 Members | 1,969 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,397 software developers and data experts.

New process continuous I/O Redirection

Hi!

I'm writing a small program in C# that uses an external CYGWIN compiled console application. That application takes 5 seconds to initialize, but after it does, i can send some text and get response almoust instantly. That means I can send new parts of text again add again without restarting app, that programm continuously process its input. I will send lot of text parts to that program, so I decided to redirect it IO so I wont lose 5 sec per text-part of execution time. Here's the part of my code
Expand|Select|Wrap|Line Numbers
  1. p = new Process();              
  2. ProcessStartInfo psI = new ProcessStartInfo(Directory.GetCurrentDirectory() + "\\tagger\\bin\\analyzer.exe");              
  3. psI.UseShellExecute = false;              
  4. psI.Arguments = " -f en.cfg --outf tagged";              
  5. psI.RedirectStandardInput = true;              
  6. psI.RedirectStandardOutput = true;              
  7. psI.CreateNoWindow = false;              
  8. psI.WorkingDirectory = Directory.GetCurrentDirectory() + "\\tagger\\bin\\";                        
  9. p.StartInfo = psI;              
  10. p.Start();              
  11. sw = p.StandardInput;              
  12. sr = p.StandardOutput;                      
  13. sw.AutoFlush = true;
but I was really confused when I get known that I can read the program output ONLY after I close its input, so I cannot send anymore without restarting...
From MSDN:
Expand|Select|Wrap|Line Numbers
  1.  
  2. // End the input stream to the sort command.           
  3. // When the stream closes, the sort command           
  4. // writes the sorted text lines to the            
  5. // console.           
  6. myStreamWriter.Close();  
  7.  
Is ther any ways of avoiding that? I mean I need to be able to continuously write to that program and read its responses.
Thanx in advance!
Feb 24 '08 #1
5 1087
Plater
7,872 Expert 4TB
Don't close the stream until you are done. I don't see what is not obvious about that?
Feb 25 '08 #2
well, If I dont close the stream external program will not get stream's data. The problem is that after I close the stream I cannot reopen it without restarting external program.
Feb 26 '08 #3
Plater
7,872 Expert 4TB
Are you doing a Flush() on the stream to force the data to be written?
Once you close a redirected stream like that, it's gone. So closing it is not what you want to do I wouldn't think
Feb 26 '08 #4
Flush doesnt sends any data here. Of course I tried.
Feb 27 '08 #5
Plater
7,872 Expert 4TB
Well I don't know what kind of strange setup you are using, it works for every program I've ever tried.
What do your commands look like?
Feb 27 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: uwnewsgroup | last post by:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and try to get its standard output by using Process.getOutputStream(), it blocks forever. I tried it using Java 1.4 and...
1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
5
by: Joseph | last post by:
Hello, I have a C# program that builds a txt file and then, calls an external exe (this external exe simply imports this txt file into a DBF (DBase) file. (we copy a template of the DBF file into...
3
by: Pat | last post by:
Hello, I've used Sum() to total bound fields on a continuous form with no problem. However, I now have a continuous form, on which I use an unbound field to calculate the number of hours between...
2
by: Jacek | last post by:
Hello! My application has to use external native library writing to stdout and stdin. My goal is to redirect output within running process (no chance to do that in child process - Process class...
4
by: Marc Jennings | last post by:
Hi all, I want to run an external app from an assembly. Simple enough... > Process ExtProcess = new Process(); > ExtProcess.StartInfo.FileName = myAppName; > ExtProcess.StartInfo.Arguments =...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.