Browse Source

--- Merging r14556 into '.':
U rtl/win/sysutils.pp
--- Merging r14572 into '.':
U rtl/unix/sysutils.pp
U rtl/nds/sysutils.pp
U rtl/morphos/sysutils.pp
U rtl/watcom/sysutils.pp
U rtl/macos/sysutils.pp
U rtl/wince/sysutils.pp
U rtl/netwlibc/sysutils.pp
U rtl/go32v2/sysutils.pp
U rtl/gba/sysutils.pp
U rtl/emx/sysutils.pp
G rtl/win/sysutils.pp
U rtl/os2/sysutils.pp
U rtl/netware/sysutils.pp
U rtl/amiga/sysutils.pp
U rtl/objpas/sysutils/osutilsh.inc
--- Merging r14618 into '.':
U tests/utils/redir.pp

# revisions: 14556,14572,14618
------------------------------------------------------------------------
r14556 | marco | 2010-01-06 20:50:09 +0100 (Wed, 06 Jan 2010) | 2 lines
Changed paths:
M /trunk/rtl/win/sysutils.pp

* Windows specific overloads for ExecuteProcess that implements a hack for redir that exists for dos.exec too.
.. but then not using a global variable
------------------------------------------------------------------------
------------------------------------------------------------------------
r14572 | marco | 2010-01-07 21:49:28 +0100 (Thu, 07 Jan 2010) | 3 lines
Changed paths:
M /trunk/rtl/amiga/sysutils.pp
M /trunk/rtl/emx/sysutils.pp
M /trunk/rtl/gba/sysutils.pp
M /trunk/rtl/go32v2/sysutils.pp
M /trunk/rtl/macos/sysutils.pp
M /trunk/rtl/morphos/sysutils.pp
M /trunk/rtl/nds/sysutils.pp
M /trunk/rtl/netware/sysutils.pp
M /trunk/rtl/netwlibc/sysutils.pp
M /trunk/rtl/objpas/sysutils/osutilsh.inc
M /trunk/rtl/os2/sysutils.pp
M /trunk/rtl/unix/sysutils.pp
M /trunk/rtl/watcom/sysutils.pp
M /trunk/rtl/win/sysutils.pp
M /trunk/rtl/wince/sysutils.pp

* Revised yesterday solution to a more general one. Executeprocess gets
another parameter, a set type with flags, default = []

------------------------------------------------------------------------
------------------------------------------------------------------------
r14618 | marco | 2010-01-11 20:45:24 +0100 (Mon, 11 Jan 2010) | 5 lines
Changed paths:
M /trunk/tests/utils/redir.pp

* cleanup of redir. I hope this solves win32 lfn problems, while preserving execinheritshandles functionality.
* removed TP/1.0
* switched windows to sysutils.executeprocess using new execinheritshandles
* new execinherits executeprocess implementation local for 2.4.0 (and 2.4.1, though that is no longer necessary after merge)

------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@14763 -

marco 15 years ago
parent
commit
67029dbba9

+ 2 - 2
rtl/amiga/sysutils.pp

@@ -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;

+ 2 - 2
rtl/emx/sysutils.pp

@@ -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;

+ 2 - 2
rtl/gba/sysutils.pp

@@ -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;

+ 2 - 2
rtl/go32v2/sysutils.pp

@@ -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;

+ 2 - 2
rtl/macos/sysutils.pp

@@ -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;
 
 

+ 2 - 2
rtl/morphos/sysutils.pp

@@ -586,7 +586,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;
@@ -633,7 +633,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;

+ 2 - 2
rtl/nds/sysutils.pp

@@ -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;

+ 2 - 2
rtl/netware/sysutils.pp

@@ -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;

+ 2 - 2
rtl/netwlibc/sysutils.pp

@@ -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;

+ 4 - 3
rtl/objpas/sysutils/osutilsh.inc

@@ -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: Array of AnsiString):integer;
-
+function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):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;

+ 2 - 2
rtl/os2/sysutils.pp

@@ -938,7 +938,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;
@@ -1050,7 +1050,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;

+ 2 - 2
rtl/unix/sysutils.pp

@@ -1144,7 +1144,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;
@@ -1209,7 +1209,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;

+ 2 - 2
rtl/watcom/sysutils.pp

@@ -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;

+ 8 - 5
rtl/win/sysutils.pp

@@ -837,7 +837,8 @@ begin
 end;
 end;
 
 
 
 
-function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
+function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
+// win specific  function
 var
 var
   SI: TStartupInfo;
   SI: TStartupInfo;
   PI: TProcessInformation;
   PI: TProcessInformation;
@@ -845,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);
@@ -864,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, False,$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;
@@ -889,7 +892,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;
@@ -902,7 +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);
+  ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
 end;
 end;
 
 
 Procedure Sleep(Milliseconds : Cardinal);
 Procedure Sleep(Milliseconds : Cardinal);

+ 2 - 2
rtl/wince/sysutils.pp

@@ -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;

+ 141 - 173
tests/utils/redir.pp

@@ -17,6 +17,7 @@
 Unit Redir;
 Unit Redir;
 Interface
 Interface
 
 
+{$mode objfpc}
 {$H+}
 {$H+}
 {$R-}
 {$R-}
 {$ifndef Linux}
 {$ifndef Linux}
@@ -25,9 +26,6 @@ Interface
 {$endif}
 {$endif}
 {$endif}
 {$endif}
 
 
-{$ifdef TP}
-{$define implemented}
-{$endif TP}
 {$ifdef Go32v2}
 {$ifdef Go32v2}
 {$define implemented}
 {$define implemented}
 {$endif}
 {$endif}
@@ -53,11 +51,6 @@ Interface
 {$define implemented}
 {$define implemented}
 {$endif}
 {$endif}
 
 
-{ be sure msdos is not set for FPC compiler }
-{$ifdef FPC}
-{$UnDef MsDos}
-{$endif FPC}
-
 Var
 Var
   IOStatus                   : Integer;
   IOStatus                   : Integer;
   RedirErrorOut,RedirErrorIn,
   RedirErrorOut,RedirErrorIn,
@@ -90,10 +83,17 @@ const
 
 
 Implementation
 Implementation
 
 
-{$if defined(macos) or defined(windows) or defined(shell_implemented) or defined(go32v2)}
+//or defined(windows)
+{$if defined(macos) or defined(shell_implemented) or defined(go32v2)}
 {$define usedos}
 {$define usedos}
 {$endif}
 {$endif}
 
 
+{$if defined(windows) and not defined(usedos)}
+  {$ifdef ver2_4}
+    {$define redirexecuteprocess}
+  {$endif}
+{$endif}
+
 Uses
 Uses
 {$ifdef go32v2}
 {$ifdef go32v2}
   go32,
   go32,
@@ -102,13 +102,15 @@ Uses
   windows,
   windows,
 {$endif windows}
 {$endif windows}
 {$ifdef unix}
 {$ifdef unix}
-  {$ifdef ver1_0}
-    linux,
-  {$else}
     baseunix,
     baseunix,
     unix,
     unix,
-  {$endif}
 {$endif unix}
 {$endif unix}
+{$ifdef redirexecuteprocess}
+    sysconst,
+
+{$endif}
+
+
 {$ifdef usedos}
 {$ifdef usedos}
   dos;
   dos;
 {$else}
 {$else}
@@ -191,64 +193,107 @@ end;
 
 
 {$ifdef implemented}
 {$ifdef implemented}
 
 
-{$ifdef TP}
 
 
-{$ifndef windows}
-const
-  UnusedHandle    = -1;
-  StdInputHandle  = 0;
-  StdOutputHandle = 1;
-  StdErrorHandle  = 2;
-{$endif windows}
+{$ifndef usedos}
+{$if defined(ver2_4_0) or defined(ver2_4_1)}
 
 
 Type
 Type
-  PtrRec = packed record
-             Ofs, Seg : Word;
-           end;
+  TExecuteFlags= set of (ExecInheritsHandles);
+{$ifdef redirexecuteprocess}
 
 
-  PHandles = ^THandles;
-  THandles = Array [Byte] of Byte;
+function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
+// win specific  function
+var
+  SI: TStartupInfo;
+  PI: TProcessInformation;
+  Proc : THandle;
+  l    : DWord;
+  CommandLine : ansistring;
+  e : EOSError;
+  ExecInherits : longbool;
+begin
+  FillChar(SI, SizeOf(SI), 0);
+  SI.cb:=SizeOf(SI);
+  SI.wShowWindow:=1;
+  { always surround the name of the application by quotes
+    so that long filenames will always be accepted. But don't
+    do it if there are already double quotes, since Win32 does not
+    like double quotes which are duplicated!
+  }
+  if pos('"',path)=0 then
+    CommandLine:='"'+path+'"'
+  else
+    CommandLine:=path;
+  if ComLine <> '' then
+    CommandLine:=Commandline+' '+ComLine+#0
+  else
+    CommandLine := CommandLine + #0;
 
 
-  PWord = ^Word;
+  ExecInherits:=ExecInheritsHandles in Flags;
+
+  if not CreateProcess(nil, pchar(CommandLine),
+    Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
+    begin
+      e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
+      e.ErrorCode:=GetLastError;
+      raise e;
+    end;
+  Proc:=PI.hProcess;
+  if WaitForSingleObject(Proc, dword($ffffffff)) <> $ffffffff then
+    begin
+      GetExitCodeProcess(Proc,l);
+      CloseHandle(Proc);
+      CloseHandle(PI.hThread);
+      result:=l;
+    end
+  else
+    begin
+      e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
+      e.ErrorCode:=GetLastError;
+      CloseHandle(Proc);
+      CloseHandle(PI.hThread);
+      raise e;
+    end;
+end;
+{$else}
+function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
+begin
+    result:=ExecuteProcess(path,comline);
+end;
+{$endif}
+{$ifend}
+{$endif}
 
 
-Var
-  MinBlockSize : Word;
-  MyBlockSize  : Word;
-  Handles      : PHandles;
-  PrefSeg      : Word;
-  OldHandleOut,OldHandleIn,OldHandleError    : Byte;
-{$endif TP}
 
 
 var
 var
   TempHOut, TempHIn,TempHError : longint;
   TempHOut, TempHIn,TempHError : longint;
 
 
 {
 {
-For linux the following functions exist
+For Unix the following functions exist
 Function  fpdup(oldfile:longint;var newfile:longint):Boolean;
 Function  fpdup(oldfile:longint;var newfile:longint):Boolean;
 Function  fpdup2(oldfile,newfile:longint):Boolean;
 Function  fpdup2(oldfile,newfile:longint):Boolean;
 Function  fpClose(fd:longint):boolean;
 Function  fpClose(fd:longint):boolean;
 }
 }
 {$ifdef go32v2}
 {$ifdef go32v2}
 
 
-function dup(fh : longint;var nh : longint) : boolean;
+function fpdup(fh : longint) : longint;
 var
 var
   Regs : Registers;
   Regs : Registers;
 begin
 begin
     Regs.ah:=$45;
     Regs.ah:=$45;
     Regs.bx:=fh;
     Regs.bx:=fh;
     MsDos (Regs);
     MsDos (Regs);
-    dup:=true;
     If (Regs.Flags and fCarry)=0 then
     If (Regs.Flags and fCarry)=0 then
-      nh:=Regs.Ax
+      fpdup:=Regs.Ax
     else
     else
-      dup:=false;
+      fpdup:=-1;
 end;
 end;
 
 
-function dup2(fh,nh : longint) : boolean;
+function fpdup2(fh,nh : longint) : longint;
 var
 var
   Regs : Registers;
   Regs : Registers;
 begin
 begin
-    dup2:=true;
+    fpdup2:=0;
     If fh=nh then
     If fh=nh then
       exit;
       exit;
     Regs.ah:=$46;
     Regs.ah:=$46;
@@ -256,61 +301,36 @@ begin
     Regs.cx:=nh;
     Regs.cx:=nh;
     MsDos (Regs);
     MsDos (Regs);
     If (Regs.Flags and fCarry)<>0 then
     If (Regs.Flags and fCarry)<>0 then
-      dup2:=false;
-end;
-
-{$ifndef ver1_0}
-function fpdup(fh:longint):longint;
-begin
-  if not dup(fh,fpdup) then
-   fpdup:=-1;
-end;
-
-function fpdup2(fh,nh:longint):longint;
-begin
-  if dup2(fh,nh) then
-   fpdup2:=0
-  else
-   fpdup2:=-1;
+      fpdup2:=-1;
 end;
 end;
-{$endif ver1_0}
 
 
-
-Function {$ifdef ver1_0}fdclose{$else}fpclose{$endif} (Handle : Longint) : boolean;
+Function fpclose (Handle : Longint) : boolean;
 var Regs: registers;
 var Regs: registers;
 begin
 begin
   Regs.Eax := $3e00;
   Regs.Eax := $3e00;
   Regs.Ebx := Handle;
   Regs.Ebx := Handle;
   MsDos(Regs);
   MsDos(Regs);
-  {$ifdef ver1_0}fdclose{$else}fpclose{$endif}:=(Regs.Flags and fCarry)=0;
+  fpclose:=(Regs.Flags and fCarry)=0;
 end;
 end;
 
 
 {$endif def go32v2}
 {$endif def go32v2}
 
 
 {$ifdef windows}
 {$ifdef windows}
-Function {$ifdef ver1_0}fdclose{$else}fpclose{$endif} (Handle : Longint) : boolean;
+Function fpclose (Handle : Longint) : boolean;
 begin
 begin
   { Do we need this ?? }
   { Do we need this ?? }
-  {$ifdef ver1_0}fdclose{$else}fpclose{$endif}:=true;
+  fpclose:=true;
 end;
 end;
 {$endif}
 {$endif}
 
 
 {$ifdef os2}
 {$ifdef os2}
-Function {$ifdef ver1_0}fdclose{$else}fpclose{$endif} (Handle : Longint) : boolean;
+Function fpclose (Handle : Longint) : boolean;
 begin
 begin
   { Do we need this ?? }
   { Do we need this ?? }
-  {$ifdef ver1_0}fdclose{$else}fpclose{$endif}:=true;
+  fpclose:=true;
 end;
 end;
 {$endif}
 {$endif}
 
 
-{$ifdef TP}
-Function {$ifdef ver1_0}fdclose{$else}fpclose{$endif} (Handle : Longint) : boolean;
-begin
-  { if executed as under GO32 this hangs the DOS-prompt }
-  {$ifdef ver1_0}fdclose{$else}fpclose{$endif}:=true;
-end;
-
-{$endif}
 
 
 {$I-}
 {$I-}
 function FileExist(const FileName : PathStr) : Boolean;
 function FileExist(const FileName : PathStr) : Boolean;
@@ -415,13 +435,8 @@ function ChangeRedirOut(Const Redir : String; AppendToFile : Boolean) : Boolean;
 {$ifdef windows}
 {$ifdef windows}
     if SetStdHandle(Std_Output_Handle,FileRec(FOUT^).Handle) then
     if SetStdHandle(Std_Output_Handle,FileRec(FOUT^).Handle) then
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}
-    dup(StdOutputHandle,TempHOut);
-    dup2(FileRec(FOUT^).Handle,StdOutputHandle);
-    {$else}
     TempHOut:=fpdup(StdOutputHandle);
     TempHOut:=fpdup(StdOutputHandle);
     fpdup2(FileRec(FOUT^).Handle,StdOutputHandle);
     fpdup2(FileRec(FOUT^).Handle,StdOutputHandle);
-    {$endif}
     if (TempHOut<>UnusedHandle) and
     if (TempHOut<>UnusedHandle) and
        (StdOutputHandle<>UnusedHandle) then
        (StdOutputHandle<>UnusedHandle) then
 {$endif not windows}
 {$endif not windows}
@@ -453,13 +468,8 @@ function ChangeRedirIn(Const Redir : String) : Boolean;
 {$ifdef windows}
 {$ifdef windows}
     if SetStdHandle(Std_Input_Handle,FileRec(FIN^).Handle) then
     if SetStdHandle(Std_Input_Handle,FileRec(FIN^).Handle) then
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}
-    dup(StdInputHandle,TempHIn);
-    dup2(FileRec(FIn^).Handle,StdInputHandle);
-    {$else}
     TempHIn:=fpdup(StdInputHandle);
     TempHIn:=fpdup(StdInputHandle);
     fpdup2(FileRec(FIn^).Handle,StdInputHandle);
     fpdup2(FileRec(FIn^).Handle,StdInputHandle);
-    {$endif}
     if (TempHIn<>UnusedHandle) and
     if (TempHIn<>UnusedHandle) and
        (StdInputHandle<>UnusedHandle) then
        (StdInputHandle<>UnusedHandle) then
 {$endif not windows}
 {$endif not windows}
@@ -511,13 +521,8 @@ function ChangeRedirError(Const Redir : String; AppendToFile : Boolean) : Boolea
 {$ifdef windows}
 {$ifdef windows}
     if SetStdHandle(Std_Error_Handle,FileRec(PF^).Handle) then
     if SetStdHandle(Std_Error_Handle,FileRec(PF^).Handle) then
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}
-    dup(StdErrorHandle,TempHError);
-    dup2(FileRec(PF^).Handle,StdErrorHandle);
-    {$else}
     TempHError:=fpdup(StdErrorHandle);
     TempHError:=fpdup(StdErrorHandle);
     fpdup2(FileRec(PF^).Handle,StdErrorHandle);
     fpdup2(FileRec(PF^).Handle,StdErrorHandle);
-    {$endif}
     if (TempHError<>UnusedHandle) and
     if (TempHError<>UnusedHandle) and
        (StdErrorHandle<>UnusedHandle) then
        (StdErrorHandle<>UnusedHandle) then
 {$endif not windows}
 {$endif not windows}
@@ -530,56 +535,17 @@ function ChangeRedirError(Const Redir : String; AppendToFile : Boolean) : Boolea
   end;
   end;
 
 
 
 
-{$IfDef MsDos}
-{Set HeapEnd Pointer to Current Used Heapsize}
-Procedure SmallHeap;assembler;
-asm
-                mov     bx,word ptr HeapPtr
-                shr     bx,4
-                inc     bx
-                add     bx,word ptr HeapPtr+2
-                mov     ax,PrefixSeg
-                sub     bx,ax
-                mov     es,ax
-                mov     ah,4ah
-                int     21h
-end;
-
-
-
-{Set HeapEnd Pointer to Full Heapsize}
-Procedure FullHeap;assembler;
-asm
-                mov     bx,word ptr HeapEnd
-                shr     bx,4
-                inc     bx
-                add     bx,word ptr HeapEnd+2
-                mov     ax,PrefixSeg
-                sub     bx,ax
-                mov     es,ax
-                mov     ah,4ah
-                int     21h
-end;
-
-{$EndIf MsDos}
-
-
   procedure RestoreRedirOut;
   procedure RestoreRedirOut;
 
 
   begin
   begin
     If not RedirChangedOut then Exit;
     If not RedirChangedOut then Exit;
-{$ifndef FPC}
-    Handles^[StdOutputHandle]:=OldHandleOut;
-    OldHandleOut:=StdOutputHandle;
-{$else}
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Output_Handle,StdOutputHandle);
     SetStdHandle(Std_Output_Handle,StdOutputHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHOut,StdOutputHandle);
+    fpdup2(TempHOut,StdOutputHandle);
 {$endif not windows}
 {$endif not windows}
-{$endif FPC}
     Close (FOUT^);
     Close (FOUT^);
-    {$ifdef ver1_0}fdclose{$else}fpclose{$endif}(TempHOut);
+    fpclose(TempHOut);
     RedirChangedOut:=false;
     RedirChangedOut:=false;
   end;
   end;
 
 
@@ -596,11 +562,11 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Input_Handle,StdInputHandle);
     SetStdHandle(Std_Input_Handle,StdInputHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHIn,StdInputHandle);
+    fpdup2(TempHIn,StdInputHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     Close (FIn^);
     Close (FIn^);
-    {$ifdef ver1_0}fdclose{$else}fpclose{$endif}(TempHIn);
+    fpclose(TempHIn);
     RedirChangedIn:=false;
     RedirChangedIn:=false;
   end;
   end;
 
 
@@ -617,7 +583,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Input_Handle,StdInputHandle);
     SetStdHandle(Std_Input_Handle,StdInputHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHIn,StdInputHandle);
+    fpdup2(TempHIn,StdInputHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     InRedirDisabled:=True;
     InRedirDisabled:=True;
@@ -637,7 +603,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Input_Handle,FileRec(FIn^).Handle);
     SetStdHandle(Std_Input_Handle,FileRec(FIn^).Handle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FileRec(FIn^).Handle,StdInputHandle);
+    fpdup2(FileRec(FIn^).Handle,StdInputHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     InRedirDisabled:=False;
     InRedirDisabled:=False;
@@ -656,7 +622,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Output_Handle,StdOutputHandle);
     SetStdHandle(Std_Output_Handle,StdOutputHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHOut,StdOutputHandle);
+    fpdup2(TempHOut,StdOutputHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     OutRedirDisabled:=True;
     OutRedirDisabled:=True;
@@ -676,7 +642,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Output_Handle,FileRec(FOut^).Handle);
     SetStdHandle(Std_Output_Handle,FileRec(FOut^).Handle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FileRec(FOut^).Handle,StdOutputHandle);
+    fpdup2(FileRec(FOut^).Handle,StdOutputHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     OutRedirDisabled:=False;
     OutRedirDisabled:=False;
@@ -695,13 +661,13 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Error_Handle,StdErrorHandle);
     SetStdHandle(Std_Error_Handle,StdErrorHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHError,StdErrorHandle);
+    fpdup2(TempHError,StdErrorHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     { don't close when redirected to STDOUT }
     { don't close when redirected to STDOUT }
     if not RedirStdErrToStdOut then
     if not RedirStdErrToStdOut then
       Close (FERR^);
       Close (FERR^);
-    {$ifdef ver1_0}fdclose{$else}fpclose{$endif}(TempHError);
+    fpclose(TempHError);
     RedirChangedError:=false;
     RedirChangedError:=false;
   end;
   end;
 
 
@@ -718,7 +684,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Error_Handle,StdErrorHandle);
     SetStdHandle(Std_Error_Handle,StdErrorHandle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(TempHError,StdErrorHandle);
+    fpdup2(TempHError,StdErrorHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     ErrorRedirDisabled:=True;
     ErrorRedirDisabled:=True;
@@ -738,7 +704,7 @@ end;
 {$ifdef windows}
 {$ifdef windows}
     SetStdHandle(Std_Error_Handle,FileRec(FErr^).Handle);
     SetStdHandle(Std_Error_Handle,FileRec(FErr^).Handle);
 {$else not windows}
 {$else not windows}
-    {$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FileRec(FERR^).Handle,StdErrorHandle);
+    fpdup2(FileRec(FERR^).Handle,StdErrorHandle);
 {$endif not windows}
 {$endif not windows}
 {$endif}
 {$endif}
     ErrorRedirDisabled:=False;
     ErrorRedirDisabled:=False;
@@ -793,9 +759,6 @@ procedure RedirEnableAll;
 
 
 procedure InitRedir;
 procedure InitRedir;
 begin
 begin
-{$ifndef FPC}
-  PrefSeg:=PrefixSeg;
-{$endif FPC}
 end;
 end;
 
 
 {$else not  implemented}
 {$else not  implemented}
@@ -1004,10 +967,7 @@ end;
 {............................................................................}
 {............................................................................}
 
 
   procedure DosExecute(ProgName, ComLine : String);
   procedure DosExecute(ProgName, ComLine : String);
-{$ifdef windows}
-    var
-      StoreInherit : BOOL;
-{$endif windows}
+
 
 
   Begin
   Begin
 {$IfDef MsDos}
 {$IfDef MsDos}
@@ -1020,55 +980,63 @@ end;
 {$ifdef UNIX}
 {$ifdef UNIX}
     IOStatus:=0;
     IOStatus:=0;
     ExecuteResult:=Shell(FixPath(Progname)+' '+Comline);
     ExecuteResult:=Shell(FixPath(Progname)+' '+Comline);
-  {$ifdef ver1_0}
-    { Signal that causes the stop of the shell }
-    IOStatus:=ExecuteResult and $7F;
-    { Exit Code seems to be in the second byte,
-      is this also true for BSD ??
-      $80 bit is a CoreFlag apparently }
-    ExecuteResult:=(ExecuteResult and $ff00) shr 8;
-  {$else}
     if ExecuteResult<0 then
     if ExecuteResult<0 then
       begin
       begin
         IOStatus:=(-ExecuteResult) and $7f;
         IOStatus:=(-ExecuteResult) and $7f;
         ExecuteResult:=((-ExecuteResult) and $ff00) shr 8;
         ExecuteResult:=((-ExecuteResult) and $ff00) shr 8;
       end;
       end;
-  {$endif}
 {$else}
 {$else}
   {$ifdef windows}
   {$ifdef windows}
-    StoreInherit:=ExecInheritsHandles;
-    ExecInheritsHandles:=true;
+
     { Avoid dialog boxes if dll loading fails }
     { Avoid dialog boxes if dll loading fails }
     SetErrorMode(SEM_FAILCRITICALERRORS);
     SetErrorMode(SEM_FAILCRITICALERRORS);
   {$endif windows}
   {$endif windows}
-    DosError:=0;
     If UseComSpec then
     If UseComSpec then
+      begin
       {$ifndef usedos}
       {$ifndef usedos}
-      Sysutils.ExecuteProcess (Getenv('COMSPEC'),'/C '+FixPath(progname)+' '+Comline)
+        try
+          ExecuteResult:=ExecuteProcess (Getenvironmentvariable('COMSPEC'),'/C '+FixPath(progname)+' '+Comline,[ExecInheritsHandles])
+        except
+          on e : exception do
+            IOStatus:=2;
+          end;
       {$else}
       {$else}
-      Exec (Getenv('COMSPEC'),'/C '+FixPath(progname)+' '+Comline)
+        DosError:=0;
+        Exec (Getenv('COMSPEC'),'/C '+FixPath(progname)+' '+Comline)
+        IOStatus:=DosError;
+        ExecuteResult:=DosExitCode;
       {$endif}
       {$endif}
+      end
     else
     else
       begin
       begin
         if LocateExeFile(progname) then
         if LocateExeFile(progname) then
-          {$ifndef usedos}
-          Sysutils.ExecuteProcess(ProgName,Comline)
-          {$else}
-          {$ifdef macos}
-          Dos.Exec(''''+ProgName+'''',Comline) {Quotes needed !}
-          {$else}
-          Dos.Exec(ProgName,Comline)
-          {$endif}
-          {$endif}
+          begin
+           {$ifndef usedos}
+            try
+              ExecuteResult:=ExecuteProcess(ProgName,Comline,[execinheritshandles])
+            except
+              on e : exception do
+              IOStatus:=2;
+              end;
+            {$else}
+              doserror:=0;
+              {$ifdef macos}
+                Dos.Exec(''''+ProgName+'''',Comline) {Quotes needed !}
+              {$else}
+                Dos.Exec(ProgName,Comline)
+             {$endif}
+             IOStatus:=DosError;
+             ExecuteResult:=DosExitCode;
+           {$endif}
+          end
         else
         else
-          DosError:=2;
+          IOStatus:=2
+          ;
       end;
       end;
   {$ifdef windows}
   {$ifdef windows}
-    ExecInheritsHandles:=StoreInherit;
     SetErrorMode(0);
     SetErrorMode(0);
   {$endif windows}
   {$endif windows}
-    IOStatus:=DosError;
-    ExecuteResult:=DosExitCode;
+
 {$endif}
 {$endif}
 {$ifdef usedos}
 {$ifdef usedos}
     SwapVectors;
     SwapVectors;