H
Horst Walter
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 ...
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 ...