473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
1 2437

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
5
by: Pengyu | last post by:
Hi, How to add a console window to a Windows application? Thank you very much in advance, Pengyu
5
by: Go Perl | last post by:
Hello Here is an interesting question which I could not solve it. I have an old dos app for which source code is lost. I just have the exe file. So I have created a front-end for that. I...
3
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
4
by: jam | last post by:
Dear All, I have a command process running xcopy in console, and now I want to execute the program Rsync After the files are copied...how could i do?? Process p10=new Process();...
2
by: O_Spring | last post by:
I am writing a program in c#. I would like to read a binary file to the standard input of a process (it is flac.exe to encode/decode some files). I have tried to use the following code : ...
2
by: ThomasG | last post by:
Hi, i've got a main (win-)application which starts a consoleapp to do some work: Dim psi As New ProcessStartInfo psi.UseShellExecute = False psi.CreateNoWindow = True...
2
by: nautonnier | last post by:
Hello, I have a C# app that spawns several processes each containing a console app written by another developer in C++. The console app was written first to be just like a console app: it...
3
by: zlf | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.