@@ -653,7 +653,9 @@ package body GNAT.Expect is
begin
for J in Descriptors'Range loop
- if Descriptors (J) /= null then
+ if Descriptors (J) /= null
+ and then Descriptors (J).Output_Fd /= Invalid_FD
+ then
Fds (Fds'First + Fds_Count) := Descriptors (J).Output_Fd;
Fds_To_Descriptor (Fds'First + Fds_Count) := J;
Fds_Count := Fds_Count + 1;
@@ -667,6 +669,14 @@ package body GNAT.Expect is
end if;
end loop;
+ if Fds_Count = 0 then
+ -- There are no descriptors to monitor, it means that process died.
+
+ Result := Expect_Process_Died;
+
+ return;
+ end if;
+
declare
Buffer : aliased String (1 .. Buffer_Size);
-- Buffer used for input. This is allocated only once, not for
new file mode 100644
@@ -0,0 +1,35 @@
+-- { dg-do run }
+
+with GNAT.Expect.TTY;
+with GNAT.OS_Lib;
+
+procedure Expect4 is
+ Pid : GNAT.Expect.TTY.TTY_Process_Descriptor;
+ Args : GNAT.OS_Lib.Argument_List (1 .. 0);
+ Result : GNAT.Expect.Expect_Match;
+
+begin
+ Pid.Non_Blocking_Spawn ("true", Args);
+
+ begin
+ Pid.Expect (Result, ".*");
+
+ raise Program_Error;
+
+ exception
+ when GNAT.Expect.Process_Died =>
+ null;
+ end;
+
+ begin
+ Pid.Expect (Result, ".*");
+
+ raise Program_Error;
+
+ exception
+ when GNAT.Expect.Process_Died =>
+ null;
+ end;
+
+ Pid.Close;
+end Expect4;
\ No newline at end of file