By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

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

P: n/a
Dv
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(ATTACH_PARENT_PROCESS), and then call
Console.WriteLine(...) 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?

Aug 13 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"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(ATTACH_PARENT_PROCESS), and then call
Console.WriteLine(...) 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]

Aug 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.