Redirecting Standard Input Output For Telnet Window
Can someone tell me why this doesnt work with telnet?
Code:
Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;
ProcessStartInfo psI = new ProcessStartInfo(@"c:\windows\system32\telnet.exe");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
err = p.StandardError;
sw.Close();
textBox1.Text = sr.ReadToEnd();
textBox1.Text += err.ReadToEnd();
It just opens a cmd prompt really quick and then closes?
Does anyone know how to redirect the I/O of a telnet window?
Re: Redirecting Standard Input Output For Telnet Window
You have not escaped your string path. Change it to either of the following...
"c:\\windows\\system32\\telnet.exe"
@"c:\windows\system32\telnet.exe"
Re: Redirecting Standard Input Output For Telnet Window
whoops... i used the @ symbol instead (i just forgot to update it on here).
The code compiles fine but it wont redirect the I/O of telnet.
Re: Redirecting Standard Input Output For Telnet Window
I tried something similar this afternoon and I couldn't get the windows to stay open for more than a fraction of a second.
I was just trying to use MSDOS's copy command to concatenate a load of files together. It worked fine but It wouldn't stay open after it had finished th copy operation it just stopped as if it was running from a bat file. Very annoying. Also I couldn't get any of the Process's events to register either.
I gues Proces isn't very well suited to commandline or console-based apps.
I'll look into it some more tomorrow.
Re: Redirecting Standard Input Output For Telnet Window
With the standard console you use the /k switch when starting it to force the window to stay open after the tasks have finished. I'm not sure if this also applies to telnet.
Re: Redirecting Standard Input Output For Telnet Window
i tried it with the /k and it did not help
C:\>telnet -h
telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
-a Attempt automatic logon. Same as -l option except uses
the currently logged on user's name.
-e Escape character to enter telnet client prompt.
-f File name for client side logging
-l Specifies the user name to log in with on the remote system.
Requires that the remote system support the TELNET ENVIRON option.
-t Specifies terminal type.
Supported term types are vt100, vt52, ansi and vtnt only.
host Specifies the hostname or IP address of the remote computer
to connect to.
port Specifies a port number or service name.
thanks for helping guys
Re: Redirecting Standard Input Output For Telnet Window