How to send to console's StandardInput from GUI app?

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

    How to send to console's StandardInput from GUI app?

    When our application is launched from Dos console, we need to print
    some message to the console. I attached our application to the console
    using AttachConsole(A TTACH_PARENT_PR OCESS), and then call
    Console.WriteLi ne(...) to print some messages there. Everything works
    fine, except that after the message has been printed, it'll require
    user to press any key exit from there.

    So, I'd like to insert a key stroke to the StandardInput
    programmtically . I know some kernel32.dll APIs can do that. But I
    wonder if there're any equivalent C# functions?

  • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

    #2
    RE: How to send to console's StandardInput from GUI app?


    "Dv" wrote:
    When our application is launched from Dos console, we need to print
    some message to the console. I attached our application to the console
    using AttachConsole(A TTACH_PARENT_PR OCESS), and then call
    Console.WriteLi ne(...) to print some messages there. Everything works
    fine, except that after the message has been printed, it'll require
    user to press any key exit from there.
    >
    So, I'd like to insert a key stroke to the StandardInput
    programmtically . I know some kernel32.dll APIs can do that. But I
    wonder if there're any equivalent C# functions?
    >
    >
    Hi DV,

    I'm not familiar with AttachConsole, and as it is a kernel32 method, I'm not
    surprised if you have to use kernel32 to further tweak the Console. You can
    change StandardInput, StandardOutput and StandardError of a Console using the
    SetIn, SetOut and SetError methods. Maybe setting StandardInput after
    AttachConsole will give you what you need.

    I'm not sure why you would need to write anything to the console if you have
    a windows application, although there may be valid reasons I'm not aware of.
    However, why do you need the input from console if you only want to override
    it anyway?

    --
    Happy Coding!
    Morten Wennevik [C# MVP]

    Comment

    Working...