mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 17:29:10 +02:00
* changed sysutils.exec to ExecuteProcess
This commit is contained in:
parent
736c418d14
commit
822ce0df68
@ -113,7 +113,7 @@ program fpc;
|
|||||||
ppcbin:='ppcppc';
|
ppcbin:='ppcppc';
|
||||||
processorname:='powerpc';
|
processorname:='powerpc';
|
||||||
{$endif powerpc}
|
{$endif powerpc}
|
||||||
versionstr:=''; { Default is just the name }
|
versionstr:=''; { Default is just the name }
|
||||||
for i:=1 to paramcount do
|
for i:=1 to paramcount do
|
||||||
begin
|
begin
|
||||||
s:=paramstr(i);
|
s:=paramstr(i);
|
||||||
@ -134,51 +134,51 @@ program fpc;
|
|||||||
writeln(ppcbin);
|
writeln(ppcbin);
|
||||||
halt(0);
|
halt(0);
|
||||||
end
|
end
|
||||||
{ -PP is a special code that will show the
|
{ -PP is a special code that will show the
|
||||||
processor and exit immediatly. It's
|
processor and exit immediatly. It's
|
||||||
main usage is for Makefile }
|
main usage is for Makefile }
|
||||||
else if processorstr='P' then
|
else if processorstr='P' then
|
||||||
begin
|
begin
|
||||||
{ report the processor }
|
{ report the processor }
|
||||||
writeln(processorname);
|
writeln(processorname);
|
||||||
halt(0);
|
halt(0);
|
||||||
end
|
end
|
||||||
else if processorstr='i386' then
|
else if processorstr='i386' then
|
||||||
ppcbin:='ppc386'
|
ppcbin:='ppc386'
|
||||||
else if processorstr='m68k' then
|
else if processorstr='m68k' then
|
||||||
ppcbin:='ppc68k'
|
ppcbin:='ppc68k'
|
||||||
else if processorstr='alpha' then
|
else if processorstr='alpha' then
|
||||||
ppcbin:='ppcapx'
|
ppcbin:='ppcapx'
|
||||||
else if processorstr='powerpc' then
|
else if processorstr='powerpc' then
|
||||||
ppcbin:='ppcppc'
|
ppcbin:='ppcppc'
|
||||||
else error('Illegal processor type "'+processorstr+'"');
|
else error('Illegal processor type "'+processorstr+'"');
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ppccommandline:=ppccommandline+s+' ';
|
ppccommandline:=ppccommandline+s+' ';
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if versionstr<>'' then
|
if versionstr<>'' then
|
||||||
ppcbin:=ppcbin+'-'+versionstr;
|
ppcbin:=ppcbin+'-'+versionstr;
|
||||||
{ find the full path to the specified exe }
|
{ find the full path to the specified exe }
|
||||||
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
|
||||||
@ -31,4 +32,4 @@ function Exec (Const Path: AnsiString; Const ComLine: AnsiString):integer;
|
|||||||
Revision 1.3 2002/09/07 16:01:22 peter
|
Revision 1.3 2002/09/07 16:01:22 peter
|
||||||
* old logs removed and tabs fixed
|
* old logs removed and tabs fixed
|
||||||
|
|
||||||
}
|
}
|
@ -140,7 +140,7 @@ type
|
|||||||
EAbort = Class(Exception);
|
EAbort = Class(Exception);
|
||||||
EAbstractError = Class(Exception);
|
EAbstractError = Class(Exception);
|
||||||
EAssertionFailed = Class(Exception);
|
EAssertionFailed = Class(Exception);
|
||||||
|
|
||||||
EPropReadOnly = class(Exception);
|
EPropReadOnly = class(Exception);
|
||||||
EPropWriteOnly = class(Exception);
|
EPropWriteOnly = class(Exception);
|
||||||
|
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -167,7 +172,7 @@ type
|
|||||||
|
|
||||||
type
|
type
|
||||||
TTerminateProc = function: Boolean;
|
TTerminateProc = function: Boolean;
|
||||||
|
|
||||||
procedure AddTerminateProc(TermProc: TTerminateProc);
|
procedure AddTerminateProc(TermProc: TTerminateProc);
|
||||||
function CallTerminateProcs: Boolean;
|
function CallTerminateProcs: Boolean;
|
||||||
|
|
||||||
@ -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
|
||||||
|
@ -21,7 +21,7 @@ interface
|
|||||||
{ force ansistrings }
|
{ force ansistrings }
|
||||||
{$H+}
|
{$H+}
|
||||||
|
|
||||||
{$DEFINE HAS_EXEC_ANSI}
|
{$DEFINE HAS_EXEC_ANSI}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Unix,errors,sysconst;
|
Unix,errors,sysconst;
|
||||||
@ -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
|
||||||
@ -572,4 +582,4 @@ end.
|
|||||||
Revision 1.12 2002/01/25 16:23:03 peter
|
Revision 1.12 2002/01/25 16:23:03 peter
|
||||||
* merged filesearch() fix
|
* merged filesearch() fix
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user