function ExecuteConsole(ExecutableChar; CommandLineChar; DirectoryChar):boolean;
const bufSize = 256;
var readPipe :THandle;
writePipe :THandle;
security :SECURITY_ATTRIBUTES;
info :STARTUPINFO;
process ROCESS_INFORMATION;
buf :array[0..bufSize-1] of char;
bytesRead Word;
text :string;
line :string;
newLinePos :integer;
begin
result:=FALSE;
security.nLength:=sizeof(security);
security.lpSecurityDescriptor:=nil;
security.bInheritHandle:=TRUE;
Application.ProcessMessages;
if CreatePipe(readPipe, writePipe, @security, 0) then
begin
ZeroMemory(@info, sizeof(info));
with info do
begin
cb := sizeof( info );
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := 0;
hStdOutput := writePipe;
hStdError := writePipe;
end;
if CreateProcess(Executable, CommandLine, nil, nil, TRUE, 0, nil, Directory, info, process) then
begin
CloseHandle( writePipe );
text:='';
while ReadFile( readPipe, buf, bufSize, bytesRead, nil) do
begin
text:=text+buf;
repeat
newLinePos:=Pos(#13, text);
if (newLinePos=0) then break;
line:=copy(text,1, newLinePos-1);
delete(text, 1, newLinePos);
Form1.Memo1.Lines.Add(line);
Application.ProcessMessages;
until Application.Terminated;
ZeroMemory(@buf, bufSize);
end;
result:=TRUE;
end;
CloseHandle( readPipe );
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ExecuteConsole('c:WINDOWSsystem32cmd.exe', PChar('/C "'+Edit1.Text+'"'), 'c:');
Edit1.Text:='';
end;
kod znaleziony na 4programmers.net
Proponuję aby wrzucić tu jakies przydatne komendy do obsługi cmd. Wiem ze kazdy moze sobie znalezc, ale fora powinny byc kopalnią wiedzy nie?? :mruga:
Jeżeli ktoś wie to prosiłbym o podanie komendy do ściągnięcia pliku z serwera ftp na dysk oraz wysłania na ftp. Wiem że trzeba użyć polecenia TFTP ale cos mi nie dziala :/
const bufSize = 256;
var readPipe :THandle;
writePipe :THandle;
security :SECURITY_ATTRIBUTES;
info :STARTUPINFO;
process ROCESS_INFORMATION;
buf :array[0..bufSize-1] of char;
bytesRead Word;
text :string;
line :string;
newLinePos :integer;
begin
result:=FALSE;
security.nLength:=sizeof(security);
security.lpSecurityDescriptor:=nil;
security.bInheritHandle:=TRUE;
Application.ProcessMessages;
if CreatePipe(readPipe, writePipe, @security, 0) then
begin
ZeroMemory(@info, sizeof(info));
with info do
begin
cb := sizeof( info );
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := 0;
hStdOutput := writePipe;
hStdError := writePipe;
end;
if CreateProcess(Executable, CommandLine, nil, nil, TRUE, 0, nil, Directory, info, process) then
begin
CloseHandle( writePipe );
text:='';
while ReadFile( readPipe, buf, bufSize, bytesRead, nil) do
begin
text:=text+buf;
repeat
newLinePos:=Pos(#13, text);
if (newLinePos=0) then break;
line:=copy(text,1, newLinePos-1);
delete(text, 1, newLinePos);
Form1.Memo1.Lines.Add(line);
Application.ProcessMessages;
until Application.Terminated;
ZeroMemory(@buf, bufSize);
end;
result:=TRUE;
end;
CloseHandle( readPipe );
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ExecuteConsole('c:WINDOWSsystem32cmd.exe', PChar('/C "'+Edit1.Text+'"'), 'c:');
Edit1.Text:='';
end;
kod znaleziony na 4programmers.net
Proponuję aby wrzucić tu jakies przydatne komendy do obsługi cmd. Wiem ze kazdy moze sobie znalezc, ale fora powinny byc kopalnią wiedzy nie?? :mruga:
Jeżeli ktoś wie to prosiłbym o podanie komendy do ściągnięcia pliku z serwera ftp na dysk oraz wysłania na ftp. Wiem że trzeba użyć polecenia TFTP ale cos mi nie dziala :/