comp.lang.ada
 help / color / mirror / Atom feed
* how to use GNAT.Expect
@ 2006-07-24 15:14 Jens K S
  2006-07-24 17:15 ` Samuel Tardieu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jens K S @ 2006-07-24 15:14 UTC (permalink / raw)


Hi all,

I new to Ada and I've been fiddling with this problem for too long
now.
Basically I want to transfer some files using Ada, but since I don't
want to create my own FTP implementation I want to start a new FTP
process from Ada (I use echo in example below). Works fine with
GNAT.OS_Lib, but when I use GNAT.Expect I get no output and an
exception?? What am I doing wrong here?

By the way, I use Xcode on OS X. Does anyone know how I can "Step
Into" code in the Expect package? This could also help me locate the
problem....

-------------------------- code -------------------------------
with Ada.Text_io;
use Ada.Text_io;
with GNAT.Expect;
with GNAT.OS_Lib;

procedure ClonesTest is

	Fd: GNAT.Expect.Process_Descriptor;
	Timeout: Integer := 10000; -- 10 sec
	Result: GNAT.Expect.Expect_Match;
	Sucess: boolean;
	P: GNAT.OS_Lib.Process_Id;
begin

	-- using Lib
	P:= GNAT.OS_Lib.Non_Blocking_Spawn("/bin/echo", (1 => new String'
("from Lib Non_Block")));
	GNAT.OS_Lib.Spawn ("/bin/echo", (1 => new String' ("from Lib Block")),
Sucess);

	-- using Expect
	GNAT.Expect.Non_Blocking_Spawn (Fd, "/bin/echo", (1 => new String'
("from Expect")));
	GNAT.Expect.Expect (Fd, Result, ".*", Timeout);
	Put_Line ("Seen: " & GNAT.Expect.Expect_Out (Fd));

    Put_Line("Hello, World again with Ada!");

end ClonesTest;


--------------- Output ---------------

from Lib Non_Block
from Lib Block

raised GNAT.EXPECT.PROCESS_DIED : g-expect.adb:594

ClonesTest has exited with status 1. 


Thanks in advance

Jens




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

* Re: how to use GNAT.Expect
  2006-07-24 15:14 how to use GNAT.Expect Jens K S
@ 2006-07-24 17:15 ` Samuel Tardieu
  2006-07-24 18:52   ` Jens K S
  2006-07-24 19:36 ` Simon Wright
  2006-07-28 18:23 ` Jens K S
  2 siblings, 1 reply; 8+ messages in thread
From: Samuel Tardieu @ 2006-07-24 17:15 UTC (permalink / raw)


>>>>> "Jens" == Jens K S <jens.schoedt@gmail.com> writes:

Jens> Basically I want to transfer some files using Ada, but since I
Jens> don't want to create my own FTP implementation I want to start a
Jens> new FTP process from Ada

Those are not the only two alternatives. You can also link with an
external libraries such as libcurl (http://curl.haxx.se/) and, for the
same price, you will get HTTP, HTTPS, and many other protocols.

Incidentally, an Ada binding already exists (I haven't tested it):
http://www.almroth.com/adacurl/index.html

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



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

* Re: how to use GNAT.Expect
  2006-07-24 17:15 ` Samuel Tardieu
@ 2006-07-24 18:52   ` Jens K S
  2006-07-25  7:33     ` Samuel Tardieu
  2006-07-25  8:51     ` Alex R. Mosteo
  0 siblings, 2 replies; 8+ messages in thread
From: Jens K S @ 2006-07-24 18:52 UTC (permalink / raw)


Thank you for the links, actually I was looking to use SFTP, but curl
looks interesting also. Any idea about my problem though?

I kind of makes me nervous when things does not work, especially now
when im venturing into a new world of Ada....

Samuel Tardieu wrote:
> >>>>> "Jens" == Jens K S <jens.schoedt@gmail.com> writes:
>
> Jens> Basically I want to transfer some files using Ada, but since I
> Jens> don't want to create my own FTP implementation I want to start a
> Jens> new FTP process from Ada
>
> Those are not the only two alternatives. You can also link with an
> external libraries such as libcurl (http://curl.haxx.se/) and, for the
> same price, you will get HTTP, HTTPS, and many other protocols.
>
> Incidentally, an Ada binding already exists (I haven't tested it):
> http://www.almroth.com/adacurl/index.html
>
>   Sam
> -- 
> Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/




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

* Re: how to use GNAT.Expect
  2006-07-24 15:14 how to use GNAT.Expect Jens K S
  2006-07-24 17:15 ` Samuel Tardieu
@ 2006-07-24 19:36 ` Simon Wright
  2006-07-28 18:23 ` Jens K S
  2 siblings, 0 replies; 8+ messages in thread
From: Simon Wright @ 2006-07-24 19:36 UTC (permalink / raw)


"Jens K S" <jens.schoedt@gmail.com> writes:

> By the way, I use Xcode on OS X. Does anyone know how I can "Step
> Into" code in the Expect package? This could also help me locate the
> problem....

The GNAT runtime is usually supplied without debug symbols (for
reasons I don't understand). If that's it, you could recompile the
runtimw with -g (you can see the compilation options in the .ali
file).



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

* Re: how to use GNAT.Expect
  2006-07-24 18:52   ` Jens K S
@ 2006-07-25  7:33     ` Samuel Tardieu
  2006-07-25  8:51     ` Alex R. Mosteo
  1 sibling, 0 replies; 8+ messages in thread
From: Samuel Tardieu @ 2006-07-25  7:33 UTC (permalink / raw)


>>>>> "Jens" == Jens K S <jens.schoedt@gmail.com> writes:

Jens> Thank you for the links, actually I was looking to use SFTP, but
Jens> curl looks interesting also. Any idea about my problem though?

No, your code works fine here on GNU/Linux:

% ./clonestest
from Lib Non_Block
from Lib Block
Seen: from Expect
Hello, World again with Ada!



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

* Re: how to use GNAT.Expect
  2006-07-24 18:52   ` Jens K S
  2006-07-25  7:33     ` Samuel Tardieu
@ 2006-07-25  8:51     ` Alex R. Mosteo
  2006-07-25 18:40       ` Jens K S
  1 sibling, 1 reply; 8+ messages in thread
From: Alex R. Mosteo @ 2006-07-25  8:51 UTC (permalink / raw)


Jens K S wrote:

> Thank you for the links, actually I was looking to use SFTP, but curl
> looks interesting also. Any idea about my problem though?

This exception

raised GNAT.EXPECT.PROCESS_DIED : g-expect.adb:594

and the fact that it works for Samuel suggests that the child process is
finishing prematurely without producing the output you expect. Perhaps even
it isn't starting? I'd check the spawning call for path/parameter problems.



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

* Re: how to use GNAT.Expect
  2006-07-25  8:51     ` Alex R. Mosteo
@ 2006-07-25 18:40       ` Jens K S
  0 siblings, 0 replies; 8+ messages in thread
From: Jens K S @ 2006-07-25 18:40 UTC (permalink / raw)



> and the fact that it works for Samuel suggests that the child process is
> finishing prematurely without producing the output you expect. Perhaps even
> it isn't starting? I'd check the spawning call for path/parameter problems.

I think you are right... it does not seem to start properly. Using
OS_Lib it works fine though. The path should be right for echo, but how
do I check the spawning call? Could you elaborate?
Still, I can not debug the GNAT library (and I guess there should be no
reason to... in a perfect world).




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

* Re: how to use GNAT.Expect
  2006-07-24 15:14 how to use GNAT.Expect Jens K S
  2006-07-24 17:15 ` Samuel Tardieu
  2006-07-24 19:36 ` Simon Wright
@ 2006-07-28 18:23 ` Jens K S
  2 siblings, 0 replies; 8+ messages in thread
From: Jens K S @ 2006-07-28 18:23 UTC (permalink / raw)


After downloading the newest AdaCore GNAT compiler for OS X the problem
is gone.

Jens K S wrote:
> Hi all,
>
> I new to Ada and I've been fiddling with this problem for too long
> now.
> Basically I want to transfer some files using Ada, but since I don't
> want to create my own FTP implementation I want to start a new FTP
> process from Ada (I use echo in example below). Works fine with
> GNAT.OS_Lib, but when I use GNAT.Expect I get no output and an
> exception?? What am I doing wrong here?
>
> By the way, I use Xcode on OS X. Does anyone know how I can "Step
> Into" code in the Expect package? This could also help me locate the
> problem....
>
> -------------------------- code -------------------------------
> with Ada.Text_io;
> use Ada.Text_io;
> with GNAT.Expect;
> with GNAT.OS_Lib;
>
> procedure ClonesTest is
>
> 	Fd: GNAT.Expect.Process_Descriptor;
> 	Timeout: Integer := 10000; -- 10 sec
> 	Result: GNAT.Expect.Expect_Match;
> 	Sucess: boolean;
> 	P: GNAT.OS_Lib.Process_Id;
> begin
>
> 	-- using Lib
> 	P:= GNAT.OS_Lib.Non_Blocking_Spawn("/bin/echo", (1 => new String'
> ("from Lib Non_Block")));
> 	GNAT.OS_Lib.Spawn ("/bin/echo", (1 => new String' ("from Lib Block")),
> Sucess);
>
> 	-- using Expect
> 	GNAT.Expect.Non_Blocking_Spawn (Fd, "/bin/echo", (1 => new String'
> ("from Expect")));
> 	GNAT.Expect.Expect (Fd, Result, ".*", Timeout);
> 	Put_Line ("Seen: " & GNAT.Expect.Expect_Out (Fd));
>
>     Put_Line("Hello, World again with Ada!");
>
> end ClonesTest;
>
>
> --------------- Output ---------------
>
> from Lib Non_Block
> from Lib Block
>
> raised GNAT.EXPECT.PROCESS_DIED : g-expect.adb:594
>
> ClonesTest has exited with status 1.
> 
> 
> Thanks in advance
> 
> Jens




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

end of thread, other threads:[~2006-07-28 18:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-24 15:14 how to use GNAT.Expect Jens K S
2006-07-24 17:15 ` Samuel Tardieu
2006-07-24 18:52   ` Jens K S
2006-07-25  7:33     ` Samuel Tardieu
2006-07-25  8:51     ` Alex R. Mosteo
2006-07-25 18:40       ` Jens K S
2006-07-24 19:36 ` Simon Wright
2006-07-28 18:23 ` Jens K S

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