unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* pipe buffering
@ 2010-09-22  1:28 Aidan Gauland
  2010-09-22  3:03 ` Aidan Gauland
  2010-09-22 20:17 ` Neil Jerram
  0 siblings, 2 replies; 6+ messages in thread
From: Aidan Gauland @ 2010-09-22  1:28 UTC (permalink / raw)
  To: guile-user

I'm trying to write a program using Guile's expect module to
automatically log into a telnet server, perform some action, and log
out.

This is the start of my program...

#! /usr/bin/guile -s
!#

(use-modules (ice-9 expect))
(use-modules (ice-9 popen))

(define ie-io (open-pipe* OPEN_BOTH
                          "/usr/bin/telnet"
                          "ienabler.canterbury.ac.nz" "259"))

Then I have a sexp for debugging, which shows that `expect' is getting
one character at a time from the telnet subprocess, since it only
prints out "Tmatch", instead of "Trying [IP address]..."

(let ((expect-port ie-io))
  (expect
   ((lambda (s eof?) (display s))
    (display "match"))))

I tried (setvbuf ie-io _IOLBF), but that produces the following error.

Backtrace:
In current input:
  18: 0* [setvbuf {#<input-output: soft 807be60>} 1]

<unnamed port>:18:1: In procedure setvbuf in expression (setvbuf ie-io _IOLBF):
<unnamed port>:18:1: Wrong type argument in position 1 (expecting open file
port): #<input-output: soft 807be60>
ABORT: (wrong-type-arg)

Can anyone offer any advice on how to get expect to see entire lines?

--Aidan

P.S. ienabler.canterbury.ac.nz is on the inside only of my
university's network, but this is what the output looks like up to the
first prompt...

Trying [IP address]...
Connected to ienabler.canterbury.ac.nz.
Escape character is '^]'.
Check Point FireWall-1 Client Authentication Server running on cpgate1
User: 





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

* Re: pipe buffering
  2010-09-22  1:28 pipe buffering Aidan Gauland
@ 2010-09-22  3:03 ` Aidan Gauland
  2010-09-22 20:17 ` Neil Jerram
  1 sibling, 0 replies; 6+ messages in thread
From: Aidan Gauland @ 2010-09-22  3:03 UTC (permalink / raw)
  To: guile-user

Aidan Gauland <aidalgol <at> no8wireless.co.nz> writes:
> I'm trying to write a program using Guile's expect module to
> automatically log into a telnet server, perform some action, and log
> out.
[snip]

I forgot to mention that I'm using Guile 1.8.7.

--Aidan





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

* Re: pipe buffering
  2010-09-22  1:28 pipe buffering Aidan Gauland
  2010-09-22  3:03 ` Aidan Gauland
@ 2010-09-22 20:17 ` Neil Jerram
  2010-09-23  6:46   ` Aidan Gauland
  2010-09-23  8:50   ` Aidan Gauland
  1 sibling, 2 replies; 6+ messages in thread
From: Neil Jerram @ 2010-09-22 20:17 UTC (permalink / raw)
  To: Aidan Gauland; +Cc: guile-user

Aidan Gauland <aidalgol@no8wireless.co.nz> writes:

> Then I have a sexp for debugging, which shows that `expect' is getting
> one character at a time from the telnet subprocess, since it only
> prints out "Tmatch", instead of "Trying [IP address]..."

Well, as the manual says:

 -- Macro: expect clause ...
     [...]   The procedures
     are called in turn after each character is read from the port,
     [...]

     The test is successful if the procedure returns a non-false value.

Your lambda returns *unspecified*, which counts as a non-false value.
So the whole (expect ...) invocation completes after reading just one
character.

     Neil



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

* Re: pipe buffering
  2010-09-22 20:17 ` Neil Jerram
@ 2010-09-23  6:46   ` Aidan Gauland
  2010-09-23  8:50   ` Aidan Gauland
  1 sibling, 0 replies; 6+ messages in thread
From: Aidan Gauland @ 2010-09-23  6:46 UTC (permalink / raw)
  To: Neil Jerram; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

On Wed, Sep 22, 2010 at 09:17:08PM +0100, Neil Jerram wrote:
> Well, as the manual says:
> 
>  -- Macro: expect clause ...
>      [...]   The procedures
>      are called in turn after each character is read from the port,
>      [...]
> 
>      The test is successful if the procedure returns a non-false value.
> 
> Your lambda returns *unspecified*, which counts as a non-false value.
> So the whole (expect ...) invocation completes after reading just one
> character.

I must've missed that "each character" bit.

Maybe it would be better to post my original program that would just
hang.  I was only using expect to print debugging messages; my
original program used expect-strings.

--Aidan

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: pipe buffering
  2010-09-22 20:17 ` Neil Jerram
  2010-09-23  6:46   ` Aidan Gauland
@ 2010-09-23  8:50   ` Aidan Gauland
  2010-09-24 23:30     ` Neil Jerram
  1 sibling, 1 reply; 6+ messages in thread
From: Aidan Gauland @ 2010-09-23  8:50 UTC (permalink / raw)
  To: guile-user

Neil Jerram <neil <at> ossau.uklinux.net> writes:
> Well, as the manual says:
> 
>  -- Macro: expect clause ...
>      [...]   The procedures
>      are called in turn after each character is read from the port,
>      [...]
> 
>      The test is successful if the procedure returns a non-false value.
> 
> Your lambda returns *unspecified*, which counts as a non-false value.
> So the whole (expect ...) invocation completes after reading just one
> character.

I must've missed that "each character" bit.

Maybe it would be better to post my original program that would just
hang.  I was only using expect to print debugging messages; my
original program used expect-strings.

--Aidan

#! /usr/bin/guile -s
!#

(use-modules (ice-9 expect))
(use-modules (ice-9 popen))

(define ie-io (open-pipe* OPEN_BOTH
                          "/usr/bin/telnet"
                          "ienabler.canterbury.ac.nz" "259"))
(let ((expect-port ie-io))
  (expect-strings
   ("^User:" (begin (display "[snip]\n" ie-io) (display "gave user")))
   ("^passwd:" (begin (display "[snip]\n" ie-io) (display "gave passwd")))))





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

* Re: pipe buffering
  2010-09-23  8:50   ` Aidan Gauland
@ 2010-09-24 23:30     ` Neil Jerram
  0 siblings, 0 replies; 6+ messages in thread
From: Neil Jerram @ 2010-09-24 23:30 UTC (permalink / raw)
  To: Aidan Gauland; +Cc: guile-user

Aidan Gauland <aidalgol@no8wireless.co.nz> writes:

> Maybe it would be better to post my original program that would just
> hang.  I was only using expect to print debugging messages; my
> original program used expect-strings.
>
> --Aidan
>
> #! /usr/bin/guile -s
> !#
>
> (use-modules (ice-9 expect))
> (use-modules (ice-9 popen))
>
> (define ie-io (open-pipe* OPEN_BOTH
>                           "/usr/bin/telnet"
>                           "ienabler.canterbury.ac.nz" "259"))
> (let ((expect-port ie-io))
>   (expect-strings
>    ("^User:" (begin (display "[snip]\n" ie-io) (display "gave user")))
>    ("^passwd:" (begin (display "[snip]\n" ie-io) (display "gave passwd")))))

Ah, thanks.

I'm afraid I think you're stuck.  The problem sounds like this one:
http://stackoverflow.com/questions/1000674/turn-off-buffering-in-pipe.
In which case, the only fix is to set up the "pipe" as a pseudo-terminal
instead, and I don't believe Guile can do that.

If you wanted to work on a patch, a possible starting point would be to
look at how Emacs implements

  (let ((process-connection-type t))
    (open-network-stream ...))

Regards,
        Neil



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

end of thread, other threads:[~2010-09-24 23:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-22  1:28 pipe buffering Aidan Gauland
2010-09-22  3:03 ` Aidan Gauland
2010-09-22 20:17 ` Neil Jerram
2010-09-23  6:46   ` Aidan Gauland
2010-09-23  8:50   ` Aidan Gauland
2010-09-24 23:30     ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).