mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 11:49:27 +02:00
* changed sysutils.exec to ExecuteProcess
This commit is contained in:
parent
736c418d14
commit
822ce0df68
@ -164,21 +164,21 @@ program fpc;
|
|||||||
findexe(ppcbin);
|
findexe(ppcbin);
|
||||||
|
|
||||||
{ call ppcXXX }
|
{ call ppcXXX }
|
||||||
swapvectors;
|
try
|
||||||
{$ifdef unix}
|
errorvalue:=ExecuteProcess(ppcbin,ppccommandline);
|
||||||
errorvalue:=SysUtils.exec(ppcbin,ppccommandline);
|
except
|
||||||
{$else}
|
error(ppcbin+' can''t be executed');
|
||||||
Dos.exec(ppcbin,ppccommandline);
|
end;
|
||||||
errorvalue:=doserror;
|
|
||||||
{$endif}
|
|
||||||
swapvectors;
|
|
||||||
if errorvalue<>0 then
|
if errorvalue<>0 then
|
||||||
error(ppcbin+' can''t be executed');
|
error(ppcbin+' can''t be executed');
|
||||||
halt(dosexitcode);
|
halt(dosexitcode);
|
||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.10 2004-01-03 09:20:45 marco
|
Revision 1.11 2004-01-05 22:41:20 florian
|
||||||
|
* changed sysutils.exec to ExecuteProcess
|
||||||
|
|
||||||
|
Revision 1.10 2004/01/03 09:20:45 marco
|
||||||
* errorhandling fixed
|
* errorhandling fixed
|
||||||
|
|
||||||
Revision 1.9 2004/01/03 09:12:23 marco
|
Revision 1.9 2004/01/03 09:12:23 marco
|
||||||
|
@ -16,13 +16,14 @@
|
|||||||
{ OS handling utilities }
|
{ OS handling utilities }
|
||||||
|
|
||||||
Function GetEnvironmentVariable(Const EnvVar : String) : String;
|
Function GetEnvironmentVariable(Const EnvVar : String) : String;
|
||||||
{$ifdef HAS_EXEC_ANSI} // define is temporarily.
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
||||||
function Exec (Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
|
||||||
{$endif}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.2 2004-01-03 08:55:58 marco
|
Revision 1.3 2004-01-05 22:37:24 florian
|
||||||
|
* changed sysutils.exec to ExecuteProcess
|
||||||
|
|
||||||
|
Revision 1.2 2004/01/03 08:55:58 marco
|
||||||
* Exec(ansistring) function
|
* Exec(ansistring) function
|
||||||
|
|
||||||
Revision 1.1 2003/10/06 21:01:06 peter
|
Revision 1.1 2003/10/06 21:01:06 peter
|
||||||
|
@ -150,6 +150,11 @@ type
|
|||||||
|
|
||||||
EPackageError = class(Exception);
|
EPackageError = class(Exception);
|
||||||
|
|
||||||
|
EOSError = class(Exception)
|
||||||
|
public
|
||||||
|
ErrorCode: DWORD;
|
||||||
|
end;
|
||||||
|
|
||||||
ESafecallException = class(Exception);
|
ESafecallException = class(Exception);
|
||||||
ENoThreadSupport = Class(Exception);
|
ENoThreadSupport = Class(Exception);
|
||||||
|
|
||||||
@ -226,7 +231,10 @@ Type
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.5 2003-11-26 22:17:42 michael
|
Revision 1.6 2004-01-05 22:37:24 florian
|
||||||
|
* changed sysutils.exec to ExecuteProcess
|
||||||
|
|
||||||
|
Revision 1.5 2003/11/26 22:17:42 michael
|
||||||
+ Merged fixbranch fixes, missing in main branch
|
+ Merged fixbranch fixes, missing in main branch
|
||||||
|
|
||||||
Revision 1.4 2003/11/26 20:12:08 michael
|
Revision 1.4 2003/11/26 20:12:08 michael
|
||||||
|
@ -478,36 +478,43 @@ begin
|
|||||||
Result:=StrPas(BaseUnix.FPGetenv(PChar(EnvVar)));
|
Result:=StrPas(BaseUnix.FPGetenv(PChar(EnvVar)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Exec (Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
||||||
var
|
var
|
||||||
pid : longint;
|
pid : longint;
|
||||||
err : longint;
|
err : longint;
|
||||||
// The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7
|
e : EOSError;
|
||||||
|
|
||||||
Begin
|
Begin
|
||||||
pid:=fpFork;
|
pid:=fpFork;
|
||||||
if pid=0 then
|
if pid=0 then
|
||||||
begin
|
begin
|
||||||
{The child does the actual exec, and then exits}
|
{The child does the actual exec, and then exits}
|
||||||
if ComLine='' then
|
if ComLine='' then
|
||||||
Execl(Path)
|
Execl(Path)
|
||||||
else
|
else
|
||||||
Execl(Path+' '+ComLine);
|
Execl(Path+' '+ComLine);
|
||||||
{If the execve fails, we return an exitvalue of 127, to let it be known}
|
{ If the execve fails, we return an exitvalue of 127, to let it be known}
|
||||||
fpExit(127);
|
fpExit(127);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if pid=-1 then {Fork failed}
|
if pid=-1 then {Fork failed}
|
||||||
begin
|
begin
|
||||||
result:=8;
|
e:=EOSError.CreateFmt('Failed to execute %s : %d',[CommandLine,-1]);
|
||||||
exit
|
e.ErrorCode:=-1;
|
||||||
|
raise e;
|
||||||
end;
|
end;
|
||||||
{We're in the parent, let's wait.}
|
|
||||||
|
{ We're in the parent, let's wait. }
|
||||||
result:=WaitProcess(pid); // WaitPid and result-convert
|
result:=WaitProcess(pid); // WaitPid and result-convert
|
||||||
|
|
||||||
if (result>=0) and (result<>127) then
|
if (result>=0) and (result<>127) then
|
||||||
result:=0
|
result:=0
|
||||||
else
|
else
|
||||||
result:=8; // perhaps one time give an better error
|
begin
|
||||||
|
e:=EOSError.CreateFmt('Failed to execute %s : %d',[CommandLine,result]);
|
||||||
|
e.ErrorCode:=result;
|
||||||
|
raise e;
|
||||||
|
end;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
@ -524,7 +531,10 @@ end.
|
|||||||
{
|
{
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.27 2004-01-03 09:09:11 marco
|
Revision 1.28 2004-01-05 22:37:15 florian
|
||||||
|
* changed sysutils.exec to ExecuteProcess
|
||||||
|
|
||||||
|
Revision 1.27 2004/01/03 09:09:11 marco
|
||||||
* Unix exec(ansistring)
|
* Unix exec(ansistring)
|
||||||
|
|
||||||
Revision 1.26 2003/11/26 20:35:14 michael
|
Revision 1.26 2003/11/26 20:35:14 michael
|
||||||
|
Loading…
Reference in New Issue
Block a user