I execute the ftp.exe cmd through a C# System.Diagnostics.Process type. And I use the following code to get the "ftp.exe" output after I programmatically enter a "help" command. But I can only get the first line of the result. And I never get to the "end" output part. The whole program seems blocked.
Process p = new Process();
p.StartInfo.FileName = @"C:\Windows\System32\ftp.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.StandardInput.WriteLine("help");
Int32 c_int = p.StandardOutput.Read();
while (c_int != -1)
{
Char c = (Char)c_int;
Console.Write(c);
c_int = p.StandardOutput.Read();
}
Console.WriteLine("end");
However, I write a simple program which only use Console.Writeline() to write some output to its StdOut stream. And I test it with the above code. It works fine. I just cannot figure out why the above code cannot work with ftp.exe? The only difference between my SimpleConsoleOutput program and the "ftp.exe" is that the ftp.exe has its own interactive command prompt.
(--------------- New Progress -----------------)
Here're some progress of my personal investigation.
I write 2 threads to write to the StdIn and read from StdOut of "ftp.exe", and the output is like this:
Commands may be abbreviated. Commands are:
Commands may be abbreviated. Commands are:
Commands may be abbreviated. Commands are:
....(exactly 16 times of above lines and then exactly 16 times of the following cmds list)
! delete literal prompt send
? debug ls put status
append dir mdelete pwd trace
...
and the last commands list is not even complete.
It seems that the help command output is divided into two parts.
The 1st part is:
Commands may be abbreviated. Commands are:
The 2nd part is:
! delete literal prompt send
? debug ls put status
append dir mdelete pwd trace
...
And all the 1st parts are wrtten to the StdOut stream of "ftp.exe" before all the 2nd parts. How coud this be?? Thanks for your comments.
I tested with other command of the "ftp.exe", and it seems normal except the "help" command