为什么这个循环跳不出来呢?

wxj211700 2008-04-26 07:07:49
do
{
BytesRead = 0;
ReadFile(ReadPipe,Buffer,ReadBuffer,&BytesRead,NULL);
Buffer[BytesRead]= '\0';
OemToAnsi(Buffer,Buffer);
Memo1->Text =Memo1->Text + String(Buffer);
}while (BytesRead < ReadBuffer);

用于创建管道并发送命令和接受执行的结果,为什么跳不出来??编译无错


完整代码:

bool TNmap_Win::RunDosInMemo(String strCmdLine, TMemo * mmoOut)
{
const int ReadBuffer=2048;
const char CommandLine[]="ping 127.0.0.1";
//bool bRet = false;
TSecurityAttributes Security;
HANDLE ReadPipe,WritePipe;
STARTUPINFO Start={sizeof(Start)};
PROCESS_INFORMATION ProcessInfo;
OVERLAPPED olp={sizeof(olp)};
char * Buffer;
DWord BytesRead,Apprunning,Result;
Security.nLength= sizeof(TSecurityAttributes);
Security.bInheritHandle =true;
Security.lpSecurityDescriptor =NULL;
if (!CreatePipe (&ReadPipe, &WritePipe, &Security, 0)==0)
{
//Edit1->Text = IntToStr(GetLastError());
Buffer= new char(ReadBuffer + 1);
memset(&Start,sizeof(Start),0);
Start.cb= sizeof(Start);
Start.hStdOutput= WritePipe;
Start.hStdError= WritePipe;
Start.dwFlags= STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
Start.wShowWindow= SW_HIDE;
if (CreateProcess(NULL,PChar(CommandLine),&Security,&Security,true,NORMAL_PRIORITY_CLASS,NULL,NULL,&Start,&ProcessInfo))
{
CloseHandle(WritePipe);
do
{
do
{
BytesRead= 0;
ReadFile(ReadPipe,Buffer,ReadBuffer,&BytesRead,NULL);
Buffer[BytesRead]= '\0';
OemToAnsi(Buffer,Buffer);
Memo1->Text= Memo1->Text + String(Buffer);
}
while (BytesRead < ReadBuffer);
//Apprunning->WaitForSingleObject(ProcessInfo.hProcess, 100);
Application->ProcessMessages();
}
while (Apprunning != WAIT_TIMEOUT);
GetExitCodeProcess(ProcessInfo.hProcess, &Result);
do
{
BytesRead = 0;
ReadFile(ReadPipe,Buffer,ReadBuffer,&BytesRead,NULL);
Buffer[BytesRead]= '\0';
OemToAnsi(Buffer,Buffer);
Memo1->Text =Memo1->Text + String(Buffer);
}while (BytesRead < ReadBuffer);
};
Memo1->Perform(WM_VSCROLL,SB_BOTTOM ,0);
Memo1->SelStart=Memo1->Text.Length() ;
Memo1->SetFocus();
delete []Buffer;
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
};
}
...全文
180 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxj211700 2008-04-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 WACR2008 的回复:]
看起来怎么这么眼熟,好像是我改的一段代码,祝你成功!
[/Quote]

被你发现了!!!
吴丁 2008-04-27
  • 打赏
  • 举报
回复
看起来怎么这么眼熟,好像是我改的一段代码,祝你成功!
wxj211700 2008-04-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 helenhf 的回复:]
每一次读到的数据都小于2048?
[/Quote]
和这个有关吗?我改4096也还是死了。。
helenhf 2008-04-26
  • 打赏
  • 举报
回复
每一次读到的数据都小于2048?

13,826

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧