Browse Source

Handle poPassInput to be able to handle interactive processes for Windows and Unix systems

git-svn-id: trunk@33021 -
pierre 9 years ago
parent
commit
6c0d2f1b36
2 changed files with 24 additions and 12 deletions
  1. 13 8
      packages/fcl-process/src/unix/process.inc
  2. 11 4
      packages/fcl-process/src/win/process.inc

+ 13 - 8
packages/fcl-process/src/unix/process.inc

@@ -261,7 +261,7 @@ Type
   TPipeEnd = (peRead,peWrite);
   TPipePair = Array[TPipeEnd] of cint;
 
-Procedure CreatePipes(Var HI,HO,HE : TPipePair; CE : Boolean);
+Procedure CreatePipes(Var HI,HO,HE : TPipePair; CI, CE : Boolean);
 
   Procedure CreatePair(Var P : TPipePair);
 
@@ -285,7 +285,8 @@ begin
   HE[peRead]:=-1;HE[peWrite]:=-1;
   Try
     CreatePair(HO);
-    CreatePair(HI);
+    if CI then
+      CreatePair(HI);
     If CE then
       CreatePair(HE);
   except
@@ -317,8 +318,8 @@ Var
   PName    : String;
 
 begin
-  If (poUsePipes in FProcessOptions) then
-    CreatePipes(HI,HO,HE,Not (poStdErrToOutPut in FProcessOptions));
+  If (poUsePipes in Options) then
+    CreatePipes(HI, HO, HE, Not(poPassInput in Options), Not (poStdErrToOutPut in Options));
   Try
     if FEnvironment.Count<>0 then
       FEnv:=StringsToPcharList(FEnvironment)
@@ -394,8 +395,11 @@ begin
                end;
             if PoUsePipes in Options then
               begin
-                FileClose(HI[peWrite]);
-                safefpdup2(HI[peRead],0);
+                if not (poPassInput in Options) then
+                  begin
+                    FileClose(HI[peWrite]);
+                    safefpdup2(HI[peRead],0);
+                  end;
                 FileClose(HO[peRead]);
                 safefpdup2(HO[peWrite],1);
                 if (poStdErrToOutPut in Options) then
@@ -431,10 +435,11 @@ begin
         FreePCharList(FEnv);
     end;
   Finally
-    if POUsePipes in FProcessOptions then
+    if POUsePipes in Options then
       begin
         FileClose(HO[peWrite]);
-        FileClose(HI[peRead]);
+        if not (POPassInput in Options) then
+          FileClose(HI[peRead]);
         if Not (poStdErrToOutPut in FProcessOptions) then
           FileClose(HE[peWrite]);
         CreateStreams(HI[peWrite],HO[peRead],HE[peRead]);

+ 11 - 4
packages/fcl-process/src/win/process.inc

@@ -187,11 +187,18 @@ begin
 end;
 
 
-Procedure CreatePipes(Var HI,HO,HE : Thandle; Var SI : TStartupInfoW; CE : Boolean; APipeBufferSize : Cardinal);
+Procedure CreatePipes(Var HI,HO,HE : Thandle; Var SI : TStartupInfoW; CI, CE : Boolean; APipeBufferSize : Cardinal);
 
 begin
-  CreatePipeHandles(SI.hStdInput,HI, APipeBufferSize);
-  DuplicateHandleFP(SI.hStdInput);
+  if CI then
+    begin
+      CreatePipeHandles(SI.hStdInput,HI, APipeBufferSize);
+      DuplicateHandleFP(SI.hStdInput);
+    end
+  else
+    begin
+      SI.hStdInput:=StdInputHandle;
+    end;
   CreatePipeHandles(HO,Si.hStdOutput, APipeBufferSize);
   DuplicateHandleFP(   Si.hStdOutput);
   if CE then begin
@@ -270,7 +277,7 @@ Var
     InitThreadAttributes(Self,FThreadAttributes);
     InitStartupInfo(Self,FStartUpInfo);
     If poUsePipes in FProcessOptions then
-      CreatePipes(HI,HO,HE,FStartupInfo,Not(poStdErrToOutPut in FProcessOptions), FPipeBufferSize);
+      CreatePipes(HI,HO,HE,FStartupInfo,Not(poPassInput in Options), Not(poStdErrToOutPut in Options), FPipeBufferSize);
     Try
       // Beware: CreateProcess can alter the strings
       // Beware: nil is not the same as a pointer to a #0