473,406 Members | 2,633 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,406 software developers and data experts.

Sending keystrokes to a console application

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 sending the keystrokes escapes me at the moment.

Is there any material online that describes the process of sending
keystrokes to a console app?
Nov 16 '05 #1
3 8921
You can redirect stdin so your can write strings to a stream and the console
will read it from std in like normal (i.e. type this.txt | myapp.exe".

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Wayne" <no**@some.isp> wrote in message
news:OT**************@TK2MSFTNGP09.phx.gbl...
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 sending the keystrokes escapes me at the moment.

Is there any material online that describes the process of sending
keystrokes to a console app?


Nov 16 '05 #2
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
You can redirect stdin so your can write strings to a stream and the console will read it from std in like normal (i.e. type this.txt | myapp.exe".


Do you have an example?
Nov 16 '05 #3
Many examples in the .net help. Here is one at
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003OCT.1033/cpref/html/frlrfsystemdiagnos
ticsprocessclassstandardinputtopic.htm

using System;
using System.IO;
using System.Diagnostics;
using System.ComponentModel;

namespace Process_StandardInput_Sample
{
class StandardInputTest
{
static void Main()
{
Console.WriteLine("Ready to sort one or more text lines...");

// Start the Sort.exe process with redirected input.
// Use the sort command to sort the input text.
Process myProcess = new Process();

myProcess.StartInfo.FileName = "Sort.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;

myProcess.Start();

StreamWriter myStreamWriter = myProcess.StandardInput;

// Prompt the user for input text lines to sort.
// Write each line to the StandardInput stream of
// the sort command.
String inputText;
int numLines = 0;
do
{
Console.WriteLine("Enter a line of text (or press the Enter key
to stop):");

inputText = Console.ReadLine();
if (inputText.Length > 0)
{
numLines ++;
myStreamWriter.WriteLine(inputText);
}
} while (inputText.Length != 0);
// Write a report header to the console.
if (numLines > 0)
{
Console.WriteLine(" {0} sorted text line(s) ", numLines);
Console.WriteLine("------------------------");
}
else
{
Console.WriteLine(" No input was sorted");
}

// End the input stream to the sort command.
// When the stream closes, the sort command
// writes the sorted text lines to the
// console.
myStreamWriter.Close();
// Wait for the sort process to write the sorted text lines.
myProcess.WaitForExit();
myProcess.Close();

}
}
}
--
William Stacey, MVP
http://mvp.support.microsoft.com

"Wayne" <no**@some.isp> wrote in message
news:#n**************@tk2msftngp13.phx.gbl...
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
You can redirect stdin so your can write strings to a stream and the

console
will read it from std in like normal (i.e. type this.txt | myapp.exe".


Do you have an example?


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Job Lot | last post by:
How can I terminate console application in Try…Catch…Finally…End Try block so that code in Finally gets executed. If I use End statement Finally does not get executed. Following is my code...
2
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
9
by: savvy | last post by:
i'm trying to compile a simple console application for sending a mail, my main idea is to schedule it to a particular time for sending mails using the windows schedular task lateron. Therefore i...
3
by: inpreet | last post by:
I am trying to build a console application in C#.Net. This application is suppose to run in background without user interaction. How can I hide console to appear?
1
by: TaeHo Yoo | last post by:
I created a console application that sends emails using smtp. This works fine on my local machine but when I run it on our server, it generates an error that says ...
1
by: VB Programmer | last post by:
I want to create a custom console application that is similar to HyperTerminal. Given an ip/port it will connect via TCP and allow the users to type commands to a certain piece of hardware...
1
by: nojetlag | last post by:
Hi there, I have a .Net Console Application (C#) that I have to use for sending email, along this process I do call the App with several parameters. So suddenly I got an error "is not a valid...
6
by: Mantorok | last post by:
Hi all I have a console application that runs every night via a scheduled task, there is a try-catch block in my Main class, whenever an error is caught it is written to a log file and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.