Send Ctrl+C in testcase.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zlf

    Send Ctrl+C in testcase.

    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.Diagnost ics.Process?
    I know I can simulate input through p.StandardInput .WriteLine, but I do not
    know what exactly input string represents "Ctrl+C".

    Thanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Send Ctrl+C in testcase.

    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]
    - mvp@spam.guard. caspershouse.co m

    "zlf" <zlfcn@hotmail. comwrote in message
    news:eATu8GRVIH A.4740@TK2MSFTN GP02.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.Diagnost ics.Process?
    I know I can simulate input through p.StandardInput .WriteLine, but I do
    not know what exactly input string represents "Ctrl+C".
    >
    Thanks
    >

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: Send Ctrl+C in testcase.


      "zlf" <zlfcn@hotmail. comwrote in message
      news:eATu8GRVIH A.4740@TK2MSFTN GP02.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.Diagnost ics.Process?
      Since console applications in Windows receive that as a console control
      signal through SetConsoleCtrlH andler, you'd use the matching function
      GenerateConsole CtrlEvent.

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

      Then p/invoke to GenerateControl CtrlEvent:
      Sends a specified signal to processes that share the console associated with the calling process.



      Comment

      • christery@gmail.com

        #4
        Re: Send Ctrl+C in testcase.

        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

        Comment

        Working...