gracefully end console app

F

Frank

Hi,
I have a console app that I want to stop gracefully by another program. The
console app already has code to intercept control-c and logoff and so on.
But how do I send a control-c to that console app from another program? The
console application is started with a Process class.

Thanks
Frank
 
N

Nicholas Paldino [.NET/C# MVP]

Frank,

Why not expose a remoting endpoint which would have a method which will
call Exit on the Environment class?

Hope this helps.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


The Console app can expose several ways to communicate with it , like :
1- TCP port
2- Named piped
3- Remoting

Any of these can be used to send a "terminate" signal , then you can call
Environment.Exit or Process.Kill to force it to terminate, or do as needed
to gracefully terminate it.

In case you do not have access to modify the app you could use
Process.StandardInput to send a ctrl+c to the app
 
F

Frank

Sending ctrl+c to standardinput does not seem to work. I don't know why not.
thanks
Frank
 
F

Frank

Yes, thats on my list
Thanks
Nicholas Paldino said:
Frank,

Why not expose a remoting endpoint which would have a method which will
call Exit on the Environment class?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Frank said:
Hi,
I have a console app that I want to stop gracefully by another program.
The console app already has code to intercept control-c and logoff and so
on. But how do I send a control-c to that console app from another
program? The console application is started with a Process class.

Thanks
Frank
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Does it works if you send any other character?

maybe you are not sending the correct sequence.

what about the other options I presented you with?
 
F

Frank

Hello,
I am sending a hex 3.
The console app does not have a read in it.
Don't need to, if I do a ctrl-c or close the window with the X in the
topright corner it stops gracefully.
Regards
Frank
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well, what about a Process.Kill ?

Not very gracefully, but ... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top