comp.lang.ada
 help / color / mirror / Atom feed
* Catching Standard_Error with GNAT.Expect
@ 2010-02-07 21:56 Gautier write-only
  2010-02-07 22:11 ` John B. Matthews
  0 siblings, 1 reply; 3+ messages in thread
From: Gautier write-only @ 2010-02-07 21:56 UTC (permalink / raw)


Hello again,
I get a nice asynchronous text output piping from an external process
thanks to GNAT.Expect (test code below). Now a last issue: when the
process is speaking through Standard_Error (like the GNAT compiler for
its messages, if I'm not mistaken), nothing make its way to
Expect_Out. Is there any switch to get the Standard_Error messages
piped ? (I guess yes, since GPS is using GNAT.Expect). TIA!
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
__
with Ada.Text_IO;                       use Ada.Text_IO;
with GNAT.OS_Lib;                       use GNAT.OS_Lib;
with GNAT.Expect;                       use GNAT.Expect;

procedure Pipe_test is
   Command : constant String := -- a command which should be long to
execute
      "gnatmake -f -Pbig_project.gpr";
   Pd      : Process_Descriptor;
   Args    : Argument_List_Access;
   Result  : Expect_Match;
begin
   Args := Argument_String_To_List (Command);
   Non_Blocking_Spawn
      (Pd,
       Command     => Args (Args'First).all,
       Args        => Args (Args'First + 1 .. Args'Last),
       Buffer_Size => 0);
   loop
      begin
         Expect (Pd, Result, Regexp => "\n", Timeout => 1_000);
         case Result is
            when Expect_Timeout =>
               Put("[timeout]"); -- no output for this time slice
            when Expect_Full_Buffer =>
               Put("[full]"); -- doesn't happen with buffer size = 0 ?
            when 1 =>
               Put(Expect_Out(Pd)); -- regexp matched
            when others =>
               Put("[?]"); -- shouldn't (and doesn't) happen
         end case;
      exception
         when Process_died => Put("[died]"); exit;
      end;
   end loop;
   Put(Expect_Out(Pd));
   Close (Pd);
end Pipe_test;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Catching Standard_Error with GNAT.Expect
  2010-02-07 21:56 Catching Standard_Error with GNAT.Expect Gautier write-only
@ 2010-02-07 22:11 ` John B. Matthews
  2010-02-07 22:21   ` Gautier write-only
  0 siblings, 1 reply; 3+ messages in thread
From: John B. Matthews @ 2010-02-07 22:11 UTC (permalink / raw)


In article 
<a996dc2c-ba18-41cd-9812-266f4a5742cc@q27g2000yqn.googlegroups.com>,
 Gautier write-only <gautier_niouzes@hotmail.com> wrote:

> I get a nice asynchronous text output piping from an external process 
> thanks to GNAT.Expect (test code below). Now a last issue: when the 
> process is speaking through Standard_Error (like the GNAT compiler 
> for its messages, if I'm not mistaken), nothing make its way to 
> Expect_Out. Is there any switch to get the Standard_Error messages 
> piped ? (I guess yes, since GPS is using GNAT.Expect). TIA!

I think setting Err_To_Out might do this, but I haven't tried:

"If Err_To_Out is True, then the standard error of the spawned 
process is connected to the standard output. This is the only way to 
get the Except subprograms also match on output on standard error."


-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Catching Standard_Error with GNAT.Expect
  2010-02-07 22:11 ` John B. Matthews
@ 2010-02-07 22:21   ` Gautier write-only
  0 siblings, 0 replies; 3+ messages in thread
From: Gautier write-only @ 2010-02-07 22:21 UTC (permalink / raw)


John B. Matthews:
> I think setting Err_To_Out might do this, but I haven't tried:

That's it - it's working!
Thanks, Gautier



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-07 22:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-07 21:56 Catching Standard_Error with GNAT.Expect Gautier write-only
2010-02-07 22:11 ` John B. Matthews
2010-02-07 22:21   ` Gautier write-only

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox