468,783 Members | 1,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Send Ctrl+C in testcase.

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
Jan 12 '08 #1
3 3726
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"zlf" <zl***@hotmail.comwrote in message
news:eA**************@TK2MSFTNGP02.phx.gbl...
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

Jan 14 '08 #2

"zlf" <zl***@hotmail.comwrote in message
news:eA**************@TK2MSFTNGP02.phx.gbl...
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/lib...55(VS.85).aspx
Jan 16 '08 #3
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
Jan 17 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jas | last post: by
2 posts views Thread by Gary | last post: by
3 posts views Thread by Str Noetika | last post: by
4 posts views Thread by F.C. | last post: by
3 posts views Thread by William Stacey [MVP] | last post: by
1 post views Thread by Gustavo Narea | last post: by
reply views Thread by Gabriel Genellina | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.