program post_commit; // Angus 27 July 2022 // just runs PostCommitMailQu.exe with the same two arguments passed by SVN // to avoid delaying SVN commit while email is sent // Warning, must be renamed post-commit.exe for SVN to run it {$APPTYPE CONSOLE} uses SysUtils, Windows, Messages, Classes, ShellAPI; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} // run a program and optionally return immediately with all process information function StartExe2 (const aAppName, aCmdLine, aWorkDir: AnsiString; ShowState: Word): TProcessInformation ; var StartupInfo : TStartupInfoA; ProcInfo : TProcessInformation; FullCommandLine: AnsiString; begin FullCommandLine := '"' + aAppName + '" ' + aCmdLine; {setup the startup information for the application } FillChar (StartupInfo, SizeOf (TStartupInfo), 0); FillChar (Result, SizeOf (Result), 0); with StartupInfo do begin cb := SizeOf (TStartupInfo); dwFlags := STARTF_FORCEONFEEDBACK ; if ShowState <> 0 then begin dwFlags := dwFlags OR STARTF_USESHOWWINDOW ; wShowWindow := ShowState ; // SW_SHOWNORMAL, SW_SHOWMINIMIZED or SW_HIDE end ; end ; // warning - GetCommandLine expects exe name as first parameter which // only seems to happen when passed combined with the commands // if CreateProcessA (PAnsiChar(aAppName), PAnsiChar(aCmdLine), nil, nil, False, // NORMAL_PRIORITY_CLASS, nil, PAnsiChar(aWorkDir), StartupInfo, // ProcInfo) then Result := ProcInfo ; if CreateProcessA (nil, PAnsiChar(FullCommandLine), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, PAnsiChar(aWorkDir), StartupInfo, ProcInfo) then Result := ProcInfo ; end; //////////////////////////////////////////////////////////////////////////////// var LogStream : TFileStream = nil; procedure LogLine(const Msg: String); var FileName : String; DateStr : String; begin try if not Assigned(LogStream) then begin FileName := ChangeFileExt(ParamStr(0), '.log'); if not FileExists(FileName) then LogStream := TFileStream.Create(FileName, fmCreate or fmShareDenyWrite) else begin LogStream := TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyWrite); LogStream.Seek(0, sofromEnd); end; end; DateTimeToString(DateStr, 'yyyy:mm:dd hh:nn:ss ', Now); LogStream.Write(Pointer(DateStr)^, Length(DateStr)); LogStream.Write(Pointer(Msg)^, Length(Msg)); LogStream.Write(PChar(#13#10)^, 2); except end; end; //////////////////////////////////////////////////////////////////////////////// var Basedir, Fname, CmdLine: String; ProcessInfo : TProcessInformation; begin try if ParamCount > 1 then begin Basedir := ExtractFilePath(ParamStr(0)); Fname := {'"' +} Basedir + 'PostCommitMailQu.exe'{ + '"'}; CmdLine := ' ' + ParamStr(1) + ' ' + ParamStr(2); try LogLine('Running: ' + Fname + ' ' + CmdLine); ProcessInfo := StartExe2(Fname, CmdLine, Basedir, SW_SHOWNORMAL); if ProcessInfo.hProcess = 0 then LogLine('Failed to run: ' + Fname) else LogLine('Run OK: ' + Fname); except on E : Exception do begin LogLine(E.ClassName + ' ' + E.Message); Exit; end; end; end else LogLine('Failed to run PostCommitMailQu.exe, No SVN Parameters to Pass'); finally FreeAndNil(LogStream); end; end.