Тема: cmd
Показать сообщение отдельно
  #5  
Старый 15.01.2009, 17:07
Аватар для Sharky
Sharky Sharky вне форума
Активный
 
Регистрация: 20.03.2007
Сообщения: 202
Репутация: 10
По умолчанию я х че понял

вот я нарыл процедурку на кмд я вообще тут ничего не понимаю что к чему и вообще какой смысл и какой алгорит
можете мне пожалуйсто последовательно расказать что тут написанно ??
Код:
procedure RunDosInMemo(CmdLine:String;AMemo:TMemo);
const
   ReadBuffer = 2400;
var
  Security        : TSecurityAttributes;
  ReadPipe,WritePipe  : THandle;
  start           : TStartUpInfo;
  ProcessInfo     : TProcessInformation;
  Buffer          : Pchar;
  BytesRead       : DWord;
  Apprunning      : DWord;
  WasOK           : Boolean;
begin
  Screen.Cursor:=CrHourGlass;

  With Security do
  begin
    nlength              := SizeOf(TSecurityAttributes);
    binherithandle       := true;
    lpsecuritydescriptor := nil;
  end;

  if Createpipe (ReadPipe, WritePipe, @Security, 0) then
    begin
      Buffer  := AllocMem(ReadBuffer + 1);
      FillChar(Start,Sizeof(Start),#0);

      start.cb          := SizeOf(start);
      start.hStdOutput  := WritePipe;
      start.hStdInput   := ReadPipe;
      start.dwFlags     := STARTF_USESTDHANDLES +
                           STARTF_USESHOWWINDOW;
      start.wShowWindow := SW_HIDE;

      if CreateProcess(nil,
          PChar(CmdLine),
          nil,//@Security,
          nil,//@Security,
          true,
          NORMAL_PRIORITY_CLASS,
          nil,
          nil,
          start,
          ProcessInfo)
      then
      begin
        CloseHandle(WritePipe);
        Apprunning := WaitForSingleObject (ProcessInfo.hProcess,100);

        try
          repeat
            WasOK:=ReadFile(ReadPipe,Buffer[0], ReadBuffer,BytesRead,nil);
            Buffer[BytesRead]:= #0;
            OemToAnsi(Buffer,Buffer);
            AMemo.Text := AMemo.text + String(Buffer);

            Application.ProcessMessages;
          until (not WasOK) or ( BytesRead = 0 );
        finally
          CloseHandle(ProcessInfo.hProcess);
          CloseHandle(ProcessInfo.hThread);
        end;
    end;

    FreeMem(Buffer);
    CloseHandle(ReadPipe);
  end;
  Screen.Cursor:=CrDefault;

end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunDosInMemo(edit1.Text,Form1.Memo1);
end;

end.
Ответить с цитированием