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

System.Diagnostics.Process for telnet.exe

P: n/a
What I try to accomplish is to run "telnet.exe" as a process in C#.

The C#-code below works with terminating commands, e.g. a
"HelloWorld.exe".

Since I'd like to communicate with "telnet" the process is still
running when I already have to read from the stream. This seems to be
the problem, since "myStreamReader.ReadLine()" is waiting for
something.

Is there a chance to force the underlying pipe to flush its output (at
least the password line should be there), so that I can read
immediately.

Any Ideas?
Regards HW

--------
Code:

namespace Telnet
{
class Telnet
{
static void Main(string[] args)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new
ProcessStartInfo("telnet", "192.168.0.1");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
StreamWriter myStreamWriter = myProcess.StandardInput;

// problem, here it hangs
// Read() and ReadToEnd() also hangs!
string myString = myStreamReader.ReadLine(); <=PROBLEM ?
....
....
....
Purpose of the application:

What I want to do is call a remote application, read the telnet
stream, search for a string (e.g. password) and respond (e.g. by
sending he "pw")

The reason why I do not want to use a library is that I have to extend
the programm later using ssh, rsh ...
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Horst,

Instead of channeling the input/output through the command window, why
not use a programattic component for Telnet? Josh Mitts has developed one,
and you can find it at (watch for line wrap):

http://www.treasureonthenet.com/net/v2/projects.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Horst Walter" <un***@web.de> wrote in message
news:53**************************@posting.google.c om...
What I try to accomplish is to run "telnet.exe" as a process in C#.

The C#-code below works with terminating commands, e.g. a
"HelloWorld.exe".

Since I'd like to communicate with "telnet" the process is still
running when I already have to read from the stream. This seems to be
the problem, since "myStreamReader.ReadLine()" is waiting for
something.

Is there a chance to force the underlying pipe to flush its output (at
least the password line should be there), so that I can read
immediately.

Any Ideas?
Regards HW

--------
Code:

namespace Telnet
{
class Telnet
{
static void Main(string[] args)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new
ProcessStartInfo("telnet", "192.168.0.1");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
StreamWriter myStreamWriter = myProcess.StandardInput;

// problem, here it hangs
// Read() and ReadToEnd() also hangs!
string myString = myStreamReader.ReadLine(); <=PROBLEM ?
...
...
...
Purpose of the application:

What I want to do is call a remote application, read the telnet
stream, search for a string (e.g. password) and respond (e.g. by
sending he "pw")

The reason why I do not want to use a library is that I have to extend
the programm later using ssh, rsh ...

Nov 15 '05 #2

P: n/a
Thanks for the info. Unfortunately the Site is down.

However, my idea still is to get it going with standard (.exe)
programs, because in my particular case this would be more generic:

Otherwise I'd need a lib for telnet, one for ssh, one for rsh...

Best Regards
HW
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<#v*************@TK2MSFTNGP11.phx.gbl>...
Horst,

Instead of channeling the input/output through the command window, why
not use a programattic component for Telnet? Josh Mitts has developed one,
and you can find it at (watch for line wrap):

http://www.treasureonthenet.com/net/v2/projects.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Horst Walter" <un***@web.de> wrote in message
news:53**************************@posting.google.c om...
What I try to accomplish is to run "telnet.exe" as a process in C#.

The C#-code below works with terminating commands, e.g. a
"HelloWorld.exe".

Since I'd like to communicate with "telnet" the process is still
running when I already have to read from the stream. This seems to be
the problem, since "myStreamReader.ReadLine()" is waiting for
something.

Is there a chance to force the underlying pipe to flush its output (at
least the password line should be there), so that I can read
immediately.

Any Ideas?
Regards HW

--------
Code:

namespace Telnet
{
class Telnet
{
static void Main(string[] args)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new
ProcessStartInfo("telnet", "192.168.0.1");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
StreamWriter myStreamWriter = myProcess.StandardInput;

// problem, here it hangs
// Read() and ReadToEnd() also hangs!
string myString = myStreamReader.ReadLine(); <=PROBLEM ?
...
...
...
Purpose of the application:

What I want to do is call a remote application, read the telnet
stream, search for a string (e.g. password) and respond (e.g. by
sending he "pw")

The reason why I do not want to use a library is that I have to extend
the programm later using ssh, rsh ...

Nov 15 '05 #3

P: n/a
I found a C# telnet client for free

http://www.klausbasan.de/misc/telnet/index.html

HW
un***@web.de (Horst Walter) wrote in message news:<53**************************@posting.google. com>...
What I try to accomplish is to run "telnet.exe" as a process in C#.

The C#-code below works with terminating commands, e.g. a
"HelloWorld.exe".

Since I'd like to communicate with "telnet" the process is still
running when I already have to read from the stream. This seems to be
the problem, since "myStreamReader.ReadLine()" is waiting for
something.

Is there a chance to force the underlying pipe to flush its output (at
least the password line should be there), so that I can read
immediately.

Any Ideas?
Regards HW

--------
Code:

namespace Telnet
{
class Telnet
{
static void Main(string[] args)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new
ProcessStartInfo("telnet", "192.168.0.1");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
StreamWriter myStreamWriter = myProcess.StandardInput;

// problem, here it hangs
// Read() and ReadToEnd() also hangs!
string myString = myStreamReader.ReadLine(); <=PROBLEM ?
...
...
...
Purpose of the application:

What I want to do is call a remote application, read the telnet
stream, search for a string (e.g. password) and respond (e.g. by
sending he "pw")

The reason why I do not want to use a library is that I have to extend
the programm later using ssh, rsh ...

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.