469,578 Members | 1,724 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

System.Diagnostics.Process for telnet.exe

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
3 11182
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
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
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.

Similar topics

1 post views Thread by solex | last post: by
reply views Thread by Colin Williams | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.