Good day, dear experts. Once again, collecting brains on the floor, I appeal to your help. I'm testing the application, among other things, during the execution, information is read from the console, and some bjaka happens at that time. It is necessary to localize the problem, but I can’t not only localize it, I can’t even understand how these pipes (pipes) work, and I don’t find something in the internet of the TSeartAttributes, TStartupInfo, etc. class notation. Here is a piece of code typical of this topic, please comment on what is happening there or advise where this topic is clearly described.
function ipconfig(v_cmd:string):string; const BUFSIZE = 2000; var SecAttr: TSecurityAttributes; hReadPipe, hWritePipe: THandle; StartupInfo: TStartUpInfo; ProcessInfo: TProcessInformation; Buffer: Pchar; WaitReason,BytesRead: DWord; l_str:string; i:integer; begin with SecAttr do begin nlength:= SizeOf(TSecurityAttributes); binherithandle:= true; lpsecuritydescriptor:= nil; end; if Createpipe(hReadPipe, hWritePipe, @SecAttr, 0) then begin Buffer:= AllocMem(BUFSIZE + 1); FillChar(StartupInfo, Sizeof(StartupInfo), #0); StartupInfo.cb:= SizeOf(StartupInfo); StartupInfo.hStdOutput:= hWritePipe; StartupInfo.hStdInput:= hReadPipe; StartupInfo.dwFlags:= STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW; StartupInfo.wShowWindow:= SW_HIDE; if CreateProcess(nil, PChar('ipconfig '), @SecAttr, @SecAttr, true, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then begin repeat WaitReason:= WaitForSingleObject( ProcessInfo.hProcess,100); //Application.ProcessMessages; //WriteLn( WaitReason); until(WaitReason <> WAIT_TIMEOUT); repeat BytesRead := 0; ReadFile(hReadPipe, Buffer[0], BUFSIZE, BytesRead, nil); Buffer[BytesRead]:= #0; OemToAnsi(Buffer,Buffer); //Копим l_str := l_str + String(buffer); until(BytesRead < BUFSIZE); end; result:=l_str; FreeMem(Buffer); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); CloseHandle(hReadPipe); CloseHandle(hWritePipe); end; end;