jak zrobić taki cfancyk żeby mieć konsole windowsową <XP [ win+r -> cmd ]> w memo i za pomocą edita wydawać polecenia do niej? Sam nie umiem tego wymyśleć to proszę nie o porady bo tyle to wiem ale o kod bo to jest największa trudność dla mnie w tym przypadku. [???]
0
0
adsylam do artykulow.
kod??
przcie to podstawy prawie.
0
adsylam do artykulow
Ja notomiast odsyłam na Torry.net - widziałem tam kiedyś fajowy kodzik do obsługi konsoli w programie niekonsolowym
0
no to ja zapodam mały kodzik do przechwytywania wyników z konsoli (czyli głowna rzecz jaka Ci jest potrzebna) resztę to już tylko i wyłącznie twoja inwencja... :D
function CaptureOutput( Parser: String ): String;
const
LENBUFF = 255;
var
tmp: String;
hReadPipe, hWritePipe: THandle;
sa: TSecurityAttributes;
si: TStartupInfo;
pi: TProcessInformation;
lpBuffer: Array[0..LENBUFF] Of char;
BytesRead: Cardinal;
BytesToRead: Cardinal;
rb: Boolean;
Buffer: String;
BufPos: Integer;
FoundNewLine: Boolean;
output_line: String;
E: Exception;
begin
sa.nLength := sizeof( sa );
sa.lpSecurityDescriptor := nil;
sa.bInheritHandle := TRUE;
If Not CreatePipe( hReadPipe, hWritePipe, @sa, 0 ) Then
Begin
E := Exception.Create('Error creation Pipe');
Raise E;
E.Free;
Exit;
End;
FillChar( si, sizeof(si), 0 );
si.cb := sizeof( si );
si.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
si.wShowWindow := SW_HIDE;
si.hStdInput := 0;
si.hStdOutput := hWritePipe;
si.hStdError := hWritePipe;
If Not CreateProcess( nil, pChar( parser ), nil, nil, true, 0, nil, nil, si, pi ) Then
Begin
E := Exception.Create('Error executing command');
Raise E;
E.Free;
Exit;
End;
CloseHandle( hWritePipe );
BytesToRead := LENBUFF;
BytesRead := 0;
Buffer := '';
While ( True ) Do
Begin
lpBuffer := '';
rb := ReadFile( hReadPipe, lpBuffer, BytesToRead, BytesRead, nil );
If ( Not rb ) Then
If ( length( Buffer ) = 0 ) Then Break;
Buffer := Buffer + lpBuffer;
foundNewLine := False;
BufPos := Pos( #13, Buffer);
If ( BufPos > 0 ) Then
begin
foundNewLine := True;
output_line := Copy( Buffer, 1, BufPos-1 );
// Here you have in output_line, the console output line by line.
tmp := tmp + output_line;
// shift remainder of buffer down
Buffer := Copy( Buffer, BufPos+2, LENBUFF );
BytesToRead := LENBUFF - Length( Buffer );
End Else
Begin
BytesToRead := LENBUFF;
tmp := tmp + Buffer;
Buffer := '';
End;
If not foundNewLine Then
Begin
If ( BytesRead = LENBUFF ) Then
Begin
E := Exception.Create('Long line. Increase buffer length');
Raise E;
E.Free;
End Else
BytesToRead := LENBUFF - Length( Buffer );
End;
End;
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( hReadPipe );
Result := tmp;
end;
kod wygooglowany po iluś tam godzinach szukania...