Я пытаюся написать оболочку для командной строки использовал вот такой код:
| Код | procedure TForm1.Button2Click(Sender: TObject); var SA: TSecurityAttributes; SI: TStartupInfo; PI: TProcessInformation; StdOutPipeRead, StdOutPipeWrite: THandle; WasOK: Boolean; Buffer: array[0..255] of Char; BytesRead,BytesWrite: Cardinal; workDir,StdInput:string; Buf : pchar;
begin Application.ProcessMessages; with SA do begin nLength := SizeOf(SA); bInheritHandle := True; lpSecurityDescriptor := nil; end; CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0 ); try with SI do begin FillChar(SI, SizeOf(SI), 0); cb := SizeOf(SI); dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; wShowWindow := SW_HIDE; hStdInput := GetStdHandle(STD_INPUT_HANDLE); hStdOutput := StdOutPipeWrite; hStdError := StdOutPipeWrite; end; WorkDir := 'c:\'; WasOK := CreateProcess(nil, 'C:\WINDOWS\system32\cmd.exe', nil, nil, True, 0, nil, PChar(WorkDir), SI, PI); if not WasOK then showmessage('error') else try buf:='dir'; WasOK:=WriteFile(StdOutPipeWrite, buf, Length(stdInput), BytesWrite, nil); //*************** if not WasOk then ShowMessage('Can not write'); CloseHandle(StdOutPipeWrite); repeat WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil); if BytesRead > 0 then begin Buffer[BytesRead] := #0; OemToAnsi(Buffer,Buffer); memo1.Lines.Add(Buffer); end; until not WasOk or (BytesRead = 0); WaitForSingleObject(PI.hProcess, INFINITE); finally CloseHandle(PI.hThread); CloseHandle(PI.hProcess); end; finally CloseHandle(StdOutPipeRead); end; end;
|
но в масте отмеченом * какаето ошибка и дирекекторию оно не пролистивает 
Получается я знаю как считать данные с консоли но не знаю как их передать Подскажите может кто-то с етим работал
ЗЫ: вариант тапа: WasOK := CreateProcess(nil, 'C:\WINDOWS\system32\cmd.exe /c dir', nil, nil, True, 0, nil, PChar(WorkDir), SI, PI); я знаю но он не подходит надо типа в рунтайм
|