mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-11 09:49:15 +02:00
* Revised yesterday solution to a more general one. Executeprocess gets
another parameter, a set type with flags, default = [] git-svn-id: trunk@14572 -
This commit is contained in:
parent
67ae263dd9
commit
8e9a7e14ad
@ -583,7 +583,7 @@ begin
|
|||||||
Result:=Dos.EnvStr(Index);
|
Result:=Dos.EnvStr(Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString):
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
|
||||||
integer;
|
integer;
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
@ -605,7 +605,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
I: integer;
|
I: integer;
|
||||||
|
@ -1130,7 +1130,7 @@ end;
|
|||||||
{$ASMMODE DEFAULT}
|
{$ASMMODE DEFAULT}
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString):
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
|
||||||
integer;
|
integer;
|
||||||
var
|
var
|
||||||
HQ: THandle;
|
HQ: THandle;
|
||||||
@ -1199,7 +1199,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
@ -261,13 +261,13 @@ begin
|
|||||||
result := '';
|
result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString): integer;
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
begin
|
begin
|
||||||
result := -1;
|
result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
begin
|
begin
|
||||||
result := -1;
|
result := -1;
|
||||||
end;
|
end;
|
||||||
|
@ -769,7 +769,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
var
|
var
|
||||||
e : EOSError;
|
e : EOSError;
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
@ -792,7 +792,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
@ -661,7 +661,7 @@ begin
|
|||||||
Result:='';
|
Result:='';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
var
|
var
|
||||||
s: AnsiString;
|
s: AnsiString;
|
||||||
wdpath: AnsiString;
|
wdpath: AnsiString;
|
||||||
@ -696,7 +696,7 @@ Begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ begin
|
|||||||
Result:=Dos.EnvStr(Index);
|
Result:=Dos.EnvStr(Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString):
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
|
||||||
integer;
|
integer;
|
||||||
var
|
var
|
||||||
tmpPath: AnsiString;
|
tmpPath: AnsiString;
|
||||||
@ -624,7 +624,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
I: integer;
|
I: integer;
|
||||||
|
@ -261,13 +261,13 @@ begin
|
|||||||
result := '';
|
result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString): integer;
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
begin
|
begin
|
||||||
result := -1;
|
result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
begin
|
begin
|
||||||
result := -1;
|
result := -1;
|
||||||
end;
|
end;
|
||||||
|
@ -533,7 +533,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
e : EOSError;
|
e : EOSError;
|
||||||
@ -557,7 +557,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
@ -593,7 +593,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
var
|
var
|
||||||
params:array of AnsiString;
|
params:array of AnsiString;
|
||||||
count,i: longint;
|
count,i: longint;
|
||||||
@ -646,7 +646,7 @@ end;
|
|||||||
|
|
||||||
const maxargs=256;
|
const maxargs=256;
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
var c : comstr;
|
var c : comstr;
|
||||||
i : integer;
|
i : integer;
|
||||||
args : array[0..maxargs+1] of pchar;
|
args : array[0..maxargs+1] of pchar;
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
**********************************************************************}
|
**********************************************************************}
|
||||||
|
|
||||||
|
Type TExecuteFlags = Set of ( ExecInheritsHandles);
|
||||||
|
|
||||||
{ OS handling utilities }
|
{ OS handling utilities }
|
||||||
|
|
||||||
{$ifdef HAS_OSERROR}
|
{$ifdef HAS_OSERROR}
|
||||||
@ -24,9 +26,8 @@ Function GetEnvironmentString(Index : Integer) : String;
|
|||||||
{$IFDEF HAS_SLEEP}
|
{$IFDEF HAS_SLEEP}
|
||||||
procedure Sleep(milliseconds: Cardinal);
|
procedure Sleep(milliseconds: Cardinal);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
|
|
||||||
|
|
||||||
Function GetTempDir(Global : Boolean) : String;
|
Function GetTempDir(Global : Boolean) : String;
|
||||||
Function GetTempDir : String;
|
Function GetTempDir : String;
|
||||||
|
@ -939,7 +939,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString):
|
function ExecuteProcess (const Path: AnsiString; const ComLine: AnsiString;Flags:TExecuteFlags=[]):
|
||||||
integer;
|
integer;
|
||||||
var
|
var
|
||||||
HQ: THandle;
|
HQ: THandle;
|
||||||
@ -1051,7 +1051,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
@ -1141,7 +1141,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
var
|
var
|
||||||
pid : longint;
|
pid : longint;
|
||||||
e : EOSError;
|
e : EOSError;
|
||||||
@ -1206,7 +1206,7 @@ Begin
|
|||||||
end;
|
end;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array Of AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
pid : longint;
|
pid : longint;
|
||||||
|
@ -776,7 +776,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
e : EOSError;
|
e : EOSError;
|
||||||
@ -800,7 +800,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
function ExecuteProcess (const Path: AnsiString;
|
function ExecuteProcess (const Path: AnsiString;
|
||||||
const ComLine: array of AnsiString): integer;
|
const ComLine: array of AnsiString;Flags:TExecuteFlags=[]): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
@ -60,10 +60,6 @@ function GetFileVersion(const AFileName: string): Cardinal;
|
|||||||
|
|
||||||
procedure GetFormatSettings;
|
procedure GetFormatSettings;
|
||||||
|
|
||||||
// OS specific versions for windows, to keep redir working
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;ExecInheritsHandles:boolean):integer;
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;ExecInheritsHandles:boolean):integer;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -841,7 +837,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;ExecInheritsHandles:boolean):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
// win specific function
|
// win specific function
|
||||||
var
|
var
|
||||||
SI: TStartupInfo;
|
SI: TStartupInfo;
|
||||||
@ -850,7 +846,7 @@ var
|
|||||||
l : DWord;
|
l : DWord;
|
||||||
CommandLine : ansistring;
|
CommandLine : ansistring;
|
||||||
e : EOSError;
|
e : EOSError;
|
||||||
|
ExecInherits : longbool;
|
||||||
begin
|
begin
|
||||||
FillChar(SI, SizeOf(SI), 0);
|
FillChar(SI, SizeOf(SI), 0);
|
||||||
SI.cb:=SizeOf(SI);
|
SI.cb:=SizeOf(SI);
|
||||||
@ -869,8 +865,10 @@ begin
|
|||||||
else
|
else
|
||||||
CommandLine := CommandLine + #0;
|
CommandLine := CommandLine + #0;
|
||||||
|
|
||||||
|
ExecInherits:=ExecInheritsHandles in Flags;
|
||||||
|
|
||||||
if not CreateProcess(nil, pchar(CommandLine),
|
if not CreateProcess(nil, pchar(CommandLine),
|
||||||
Nil, Nil, ExecInheritsHandles,$20, Nil, Nil, SI, PI) then
|
Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
|
||||||
begin
|
begin
|
||||||
e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
|
e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
|
||||||
e.ErrorCode:=GetLastError;
|
e.ErrorCode:=GetLastError;
|
||||||
@ -894,13 +892,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
// os independant function
|
|
||||||
begin
|
|
||||||
result:=Executeprocess(path,comline,false);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;ExecInheritsHandles:boolean):integer;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
@ -913,13 +905,7 @@ begin
|
|||||||
CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
|
CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
|
||||||
else
|
else
|
||||||
CommandLine := CommandLine + ' ' + Comline [I];
|
CommandLine := CommandLine + ' ' + Comline [I];
|
||||||
ExecuteProcess := ExecuteProcess (Path, CommandLine,ExecInheritsHandles);
|
ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
|
||||||
end;
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
|
|
||||||
// os independant function
|
|
||||||
begin
|
|
||||||
result:=Executeprocess(path,comline,false);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure Sleep(Milliseconds : Cardinal);
|
Procedure Sleep(Milliseconds : Cardinal);
|
||||||
|
@ -647,7 +647,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
var
|
var
|
||||||
PI: TProcessInformation;
|
PI: TProcessInformation;
|
||||||
Proc : THandle;
|
Proc : THandle;
|
||||||
@ -680,7 +680,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
CommandLine: AnsiString;
|
CommandLine: AnsiString;
|
||||||
|
Loading…
Reference in New Issue
Block a user