Browse Source

Amiga, AROS, MorphOS: TProcess with simple output catching (via file)

git-svn-id: trunk@30805 -
marcus 10 years ago
parent
commit
9d46a85d1a

+ 14 - 4
packages/fcl-process/src/amicommon/pipes.inc

@@ -13,10 +13,12 @@
 
  **********************************************************************}
 
+uses
+  exec, AmigaDos;
+
 // No pipes under dos, sorry...
 
 Function CreatePipeHandles (Var Inhandle,OutHandle : THandle; APipeBufferSize : Cardinal = 1024) : Boolean;
-
 begin
   InHandle := THandle (UnusedHandle);
   OutHandle := THandle (UnusedHandle);
@@ -40,8 +42,16 @@ begin
   Raise EPipeSeek.Create (ENoSeekMsg);
 end;
 
-procedure PipeClose (const FHandle: THandle); inline;
+procedure PipeClose (const FHandle: THandle);
+var
+  Filename: array[0..255] of Char;
+  DeleteIt: Boolean;
 begin
-  if FHandle <> UnusedHandle then
-   FileClose (FHandle);
+  if (FHandle <> UnusedHandle) and (FHandle <> 0) then
+  begin
+   DeleteIt := NameFromFH(BPTR(FHandle), @(Filename[0]), 255);
+   FileClose(FHandle);
+   if DeleteIt then
+     AmigaDos.DeleteFile(@(Filename[0]));
+ end;  
 end;

+ 20 - 3
packages/fcl-process/src/amicommon/process.inc

@@ -2,6 +2,8 @@
   Dummy process.inc - the simplest version based on SysUtils.ExecuteProcess
 }
 
+uses
+  Exec, AmigaDos, Utility;
 
 Resourcestring
   SNoCommandLine        = 'Cannot execute empty command-line';
@@ -60,6 +62,9 @@ begin
    Result := S;
 end;
 
+var
+  UID: Integer = 0;
+
 Procedure TProcess.Execute;
 var
   I: integer;
@@ -67,6 +72,8 @@ var
   E2: EProcess;
   OrigDir: string;
   Params: string;
+  TempName: string;
+  cos: BPTR;
 begin
   if (ApplicationName = '') and (CommandLine = '') and (Executable = '') then
    raise EProcess.Create (SNoCommandline);
@@ -89,7 +96,7 @@ begin
     Trim (Params);
    end
   else
-   for I := 1 to Pred (Parameters.Count) do
+   for I := 0 to Pred (Parameters.Count) do
     Params := Params + ' ' + MaybeQuote (Parameters [I]);
   if (FExecutable <> '') and (ExecName = '') then
    ExecName := Executable;
@@ -106,8 +113,18 @@ begin
     GetDir (0, OrigDir);
     ChDir (FCurrentDirectory);
    end;
-  try
-   FExitCode := ExecuteProcess (ExecName, Params);
+  try   
+   cos := BPTR(0);
+   repeat
+     Inc(UID);
+     TempName := 'T:'+HexStr(FindTask(nil)) + '_'  + HexStr(Self) + '_'+ IntToStr(UID) + '_Starter.tmp';
+   until not FileExists(TempName);   
+   //sysdebugln('TProcess start: "' + ExecName + ' ' + Params+'"  >' + TempName);
+   cos := DosOpen(PChar(TempName), MODE_READWRITE);
+   FExitCode := LongInt(amigados.Execute(PChar(ExecName + ' ' + Params), BPTR(0), cos));
+   DosSeek(cos, 0, OFFSET_BEGINNING);
+   CreateStreams(0, THandle(cos),0);
+   //FExitCode := ExecuteProcess (ExecName, Params);
   except
 (* Normalize the raised exception so that it is aligned to other platforms. *)
     On E: EOSError do