Redirect StandartOutput and StandardInput at the same time without closing the executive

  • Thread starter Thread starter Ivan Lam
  • Start date Start date
I

Ivan Lam

Hi all,

Thanks for reading my post!!!

I am facing a problem that I cannot redirect StandartOutput and
StandardInput at the same time without closing the executive.

Actually, I have a console application named "etm.exe", I would like
to call it in my .net (VC) application. What I want to do is when the
user type some command in my .net application, I redirect this command
to etm.exe and also redirect the output of "etm.exe" to my .net
application. Also, I need the "etm.exe" not to be closed until I close
my .net application.

I have tried by using "process" class, I can redirect the input and
output. However, the "etm.exe" is closed every time a single command
completed.

Has anyone tried to develop a similar application?
Thanks in advance. Your help is greatly appreicated!!!

Ivan Lam
 
Couple things to look for.

In your etm.exe are you ever calling Console.Out.Flush()? This will flush
what is in the buffer to the Stream.

In your application how are you redirecting the standard output?

Process p;
p.StandardOutput.ReadToEnd().

If you are calling ReadToEnd, it will not read it until I think the stream
is closed. ie the etm.exe has exited. You might want to look at some other
methods Read, ReadLine to get better functionality.

The only time you can send information easily to another process is through
the process start info object. You can only pass command arguments to the
exe.

To pass commands to the etm.exe while it is running, you will have to look
into remoting, or some sort of RPC call to send commands to a seperate
process.

So this might have not helped you at all, but hopefully you have more
insight into your problem.

bill
 
We are working on getting access to a running process in an ASP.NET Web App
which needs to access a running process, send messages to it, on different
requests. What we did was create the process on the first request, then
withing the .exe itself, we had a while loop like while((read =
Console.ReadLine()) != null) This seems to keep the .exe running and
accepting input. Using that, we were able to have our asp.net grab hold of
the running process, and send it commands pretty easily. If you have anymore
input on this we have some issues on it we've been battling for ASP.NET such
as how to grab hold of the StandardInput Stream on a second request since the
stream is closed. Right now we cache an opened StreamWriter object but that
seems a little brittle. Any ideas on that one?

Christopher
 
Back
Top