unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
Windows, Process,FileUtil,LazUTF8;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
public
end;
const
BUF_SIZE = 2048; // Buffer size for reading the output in chunks
var
Form1: TForm1;
lProc: TProcess;
lBytesRead : longint;
lBuffer : array[1..BUF_SIZE] of byte;
lStr : TStringStream;
lPass,lPass1,st : string;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
lStr :=TStringStream.Create('');
lProc :=TProcess.Create(nil);
lProc :=TProcess.Create(Self);
lProc.Options:=[poUsePipes];
//lProc.ShowWindow:=swoHide;
lProc.Executable:='C:\Program Files\PostgreSQL\13\bin\pg_dump.exe';
lProc.Parameters.Add('-U');
lProc.Parameters.Add('postgres');
lProc.Parameters.Add('-h');
lProc.Parameters.Add('localhost');
lProc.Parameters.Add('-p');
lProc.Parameters.Add('5432');
lProc.Parameters.Add('-F');
lProc.Parameters.Add('custom');
lProc.Parameters.Add('-b');
lProc.Parameters.Add('-v');
lProc.Parameters.Add('-f');
lProc.Parameters.Add('mydb.backup');
lProc.Parameters.Add('mydb');
//lProc.Environment.Append('PGPASSWORD=superuser');
//lProc.CommandLine :='SET PGPASSWORD="superuser"';
lProc.Execute;
//lpass1:='PGPASSWORD="superuser"'+LineEnding;
//lProc.Input.Write(lPass1[1],Length(lPass1));
//st:=lProc.Output.ReadAnsiString;
//showmessage(st);
lPass :='superuser'+LineEnding;
lProc.Input.Write(lPass[1],Length(lPass));
repeat
lBytesRead :=lProc.Stderr.Read(lBuffer,BUF_SIZE);
lStr.Write(lBuffer,lBytesRead);
Memo1.Text:=lStr.DataString;
Application.ProcessMessages;
until lBytesRead=0;
if lProc.ExitStatus=0 then
ShowMessage('Proses OK')
else
ShowMessage('Proses Fail');
lProc.Free;
lStr.Free;
end;
end.