Send Ctrl+C in testcase.

  • Thread starter Thread starter zlf
  • Start date Start date
Z

zlf

Hello
I'm writing testcase for my console application. One testcase requires to
test press Ctrl+C while the application is running.
How to send Ctrl+C while running application through
System.Diagnostics.Process?
I know I can simulate input through p.StandardInput.WriteLine, but I do not
know what exactly input string represents "Ctrl+C".

Thanks
 
zlf,

If you can make the console app the active application, you could use
the SendKeys class to send a key sequence to the app.
 
zlf said:
Hello
I'm writing testcase for my console application. One testcase requires to
test press Ctrl+C while the application is running.
How to send Ctrl+C while running application through
System.Diagnostics.Process?

Since console applications in Windows receive that as a console control
signal through SetConsoleCtrlHandler, you'd use the matching function
GenerateConsoleCtrlEvent.

Looks like you'll need to use a process group and know the PID of the
process.

Then p/invoke to GenerateControlCtrlEvent:
http://msdn2.microsoft.com/en-us/library/ms683155(VS.85).aspx
 
Could be silly, but not wanting the os to know then pass it ascii char
3, wont break the exec...
like Ctrl+Break that sets of OS interrupts, as do Ctrl+C, creates
events
//CY
 
Back
Top