[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 5/5] Pascal-RTL: ExecuteProcess



+ Pascal-RTL: Implementierung von sysutils.ExecuteProcess

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/pas/lib/rtl/sysutils.pp |   37 +++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/modules/pas/lib/rtl/sysutils.pp b/src/modules/pas/lib/rtl/sysutils.pp
index ac1e5dc..934f88b 100644
--- a/src/modules/pas/lib/rtl/sysutils.pp
+++ b/src/modules/pas/lib/rtl/sysutils.pp
@@ -51,6 +51,9 @@ function c_fseek(f: longint; offset, whence: longint): longint; cdecl; external
 
 function c_feof(f: longint): boolean; cdecl; external name 'feof';
 
+function c_init_execute(cmd: PChar): dword; cdecl; external name 'init_execute';
+function c_waitpid(pid: integer; status: Pointer; flags: integer): integer; cdecl; external name 'waitpid';
+
 type
     DirEntry = record
         name:   array [1..32] of char;
@@ -162,14 +165,40 @@ begin
 end;    
 
 function ExecuteProcess(const path: AnsiString;const comline: AnsiString):LongInt;
+var
+    cmdline: String;
+    ret, pid: integer;
+    status: integer;
 begin
-    Result := 0; // FIXME
-end;    
+    cmdline := path + ' ' + comline + #0;
+
+    pid := c_init_execute(@cmdline[1]);
+    ret := c_waitpid(pid, @status, 0);
+
+    if ret = -1 then begin
+        raise EOSError.create('Konnte Programm ' + path + 'nicht ausführen');
+    end;
+
+    while (ret <> pid) and (ret <> -1) do begin
+        yield;
+        ret := c_waitpid(pid, @status, 0);
+    end;
+
+    ExecuteProcess := status;
+end;
 
 function ExecuteProcess(const path: AnsiString;const comline: Array Of AnsiString):LongInt;
+var
+    args: String;
+    i: integer;
 begin
-    Result := 0; // FIXME
-end;    
+    args := '';
+    for i := Low(comline) to High(comline) do begin
+        args := args + comline[i];
+    end;
+
+    ExecuteProcess := ExecuteProcess(path, args);
+end;
 
 procedure GetLocalTime(var systemtime: TSystemTime);
 begin
-- 
1.6.0.2