К примеру вот так: | Код | function RunCommand(const Command,Dir:string; Lines:TStrings; var CaretPos:TPoint):boolean; var StartUpInfo:TStartupInfo; ProcessInfo:TProcessInformation; PrConsole:String; pRead,pWrite,Bytes,r:cardinal; s:string; sAttr:TSecurityAttributes; pDir:PChar; begin Result:=false; sAttr.nLength:=SizeOf(SECURITY_ATTRIBUTES); sAttr.bInheritHandle:=true; sAttr.lpSecurityDescriptor:=nil; if DWord(CreatePipe(pRead,pWrite,@sAttr,0))=0 then Exit; FillChar(StartUpInfo,SizeOf(TStartUpInfo),0); StartUpInfo.cb:=SizeOf(TStartUpInfo); StartUpInfo.dwFlags:=STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW; StartUpInfo.wShowWindow:=SW_Hide; StartUpInfo.hStdOutput:=pWrite; StartUpInfo.hStdError:=pWrite; PrConsole:='cmd.exe'; s:=Trim(Command); if s<>'' then PrConsole:=PrConsole+' /K '+s; pDir:=nil; if trim(Dir)<>'' then pDir:=PChar(Dir); if CreateProcess(nil,PChar(PrConsole),nil,nil,true,NORMAL_PRIORITY_CLASS,nil,pDir,StartUpInfo,ProcessInfo) then begin WaitForSingleObject(ProcessInfo.hProcess,INFINITE); CloseHandle(ProcessInfo.hThread); CloseHandle(ProcessInfo.hProcess); PeekNamedPipe(pRead,nil,0,nil,@Bytes,nil); if Bytes<>0 then begin SetLength(s,Bytes); ReadFile(pRead,PChar(s)^,Length(s),r,nil); OemToChar(PChar(s),PChar(s)); Lines.Add(s); CaretPos:=Point(Length(trim(Lines.Strings[Lines.Count-1])),Lines.Count-1); SetLength(s,0); Result:=true; end; end; end; |
Во вложение пример использования данной функции... Ты можеш работать с Memo как буд-то ты в окне сессии Dos, т.е. вводить команды: dir, cd \, запускать приложения и т.д.
PS: Кое-что мне было лень делать... но думаю что идея будет ясна
Удачи. |