【发布时间】:2008-11-25 21:21:58
【问题描述】:
我正在使用以下代码
System::Diagnostics::Process^ p = gcnew System::Diagnostics::Process();
p->StartInfo->FileName = "tnccmd.exe";
p->StartInfo->UseShellExecute = false;
p->StartInfo->RedirectStandardInput = true;
p->StartInfo->RedirectStandardOutput = true;
p->Start();
System::IO::StreamWriter^ tnc_stdin = p->StandardInput;
System::IO::StreamReader^ tnc_stdout = p->StandardOutput;
tnc_stdin->WriteLine("connect i 127.0.0.1");
String^ prg_output = tnc_stdout->ReadToEnd();
我的问题是我无法正确读取stdout。不过,我可以轻松地写信给stdin,但现在我正在尝试实现一些错误检查代码,但它不起作用。
我正在使用的程序似乎没有写入stdout,即使它是在命令行中运行的。我可以用ftp.exe 重现bug,默认情况下Windows XP 附带。如果您将->FileName 更改为ftp.exe,则命令提示符ftp.exe 通常给出ftp> 将不会出现在prg_output 中。
现在我知道提示必须使用某种windows shell curses,我可能会混淆问题。
通常在 connect i 127.0.0.1 指令之后我应该收到 connecting to 127.0.0.1... 但我什么也没收到。
关于我做错了什么的任何提示?还有另一种我不知道的stdout吗?
编辑
我不能使用参数,因为我要写多行,就像ftp.exe。
此外,ftp.exe 会在您键入 dir 之类的命令时输出。至少当你编写未知命令时它会输出,它会抱怨Invalid command。
【问题讨论】: