Skip to content

Commit 52ec9d6

Browse files
author
Arnaud Bouchez
committed
core: added optional "jobtoclose: PHandle" parameter to RunCommandWin()
- properly implement #359
1 parent 7fdbd70 commit 52ec9d6

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/core/mormot.core.os.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5958,7 +5958,7 @@ function RunCommandWin(const cmd: TFileName; waitfor: boolean;
59585958
var processinfo: TProcessInformation; const env: TFileName = '';
59595959
options: TRunOptions = []; waitfordelayms: cardinal = INFINITE;
59605960
redirected: PRawByteString = nil; const onoutput: TOnRedirect = nil;
5961-
const wrkdir: TFileName = ''): integer;
5961+
const wrkdir: TFileName = ''; jobtoclose: PHandle = nil): integer;
59625962

59635963
type
59645964
/// how RunRedirect() or RunCommand() should try to gracefully terminate

src/core/mormot.core.os.windows.inc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,7 +4857,7 @@ function RunCommandWin(const cmd: TFileName; waitfor: boolean;
48574857
var processinfo: TProcessInformation; const env: TFileName;
48584858
options: TRunOptions; waitfordelayms: cardinal;
48594859
redirected: PRawByteString; const onoutput: TOnRedirect;
4860-
const wrkdir: TFileName): integer;
4860+
const wrkdir: TFileName; jobtoclose: PHandle): integer;
48614861
var
48624862
startupinfo: TStartupInfo; // _STARTUPINFOW or _STARTUPINFOA is equal here
48634863
security: TSecurityAttributes;
@@ -4970,6 +4970,8 @@ begin
49704970
l := 0;
49714971
rd := 0;
49724972
job := 0;
4973+
if Assigned(jobtoclose) then
4974+
jobtoclose^ := job;
49734975
if Assigned(onoutput) or
49744976
(redirected <> nil) then
49754977
if CreatePipe(rd, wr, @security, 0) then
@@ -5025,7 +5027,9 @@ begin
50255027
begin
50265028
CloseHandle(job);
50275029
job := 0;
5028-
end;
5030+
end
5031+
else if Assigned(jobtoclose) then
5032+
jobtoclose^ := job;
50295033
end;
50305034
if Assigned(onoutput) then
50315035
onoutput('', processinfo.dwProcessId);
@@ -5111,8 +5115,9 @@ begin
51115115
CloseHandle(processinfo.hThread);
51125116
if rd <> 0 then // CloseHandle(wr) has already be done
51135117
CloseHandle(rd);
5114-
if job <> 0 then
5115-
CloseHandle(job);
5118+
if (job <> 0) and
5119+
not Assigned(jobtoclose) then
5120+
CloseHandle(job); // caller should make CloseHandle(jobtoclose^)
51165121
end;
51175122

51185123
function RunRedirect(const cmd: TFileName; exitcode: PInteger;

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.10942'
1+
'2.3.10943'

0 commit comments

Comments
 (0)