guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help


From: Barak Bar Oryon
Subject: Help
Date: Tue, 30 Jan 2001 09:50:09 +0200 (IST)

I have tried to use the expect module for chatting
with an ftp process but I didn't get too far (:

I couldn't get the ftp output to the expect script.
When I tried it with another guile function it worked fine.

1) Does it related to buffering in the ftp client.
2) How can I make it work ...

Barak.

#!/usr/local/bin/guile -s
!#
;; -*- scheme -*-

(use-modules (ice-9 expect))

(define expect-thunks
  (lambda(expect-thunk command-thunk)
    (let ((pipe1 (pipe))
          (pipe2 (pipe)))
      (setvbuf (car pipe1) _IONBF)
      (setvbuf (cdr pipe1) _IONBF)
      (setvbuf (car pipe2) _IONBF)
      (setvbuf (cdr pipe2) _IONBF)
      (let ((pid (primitive-fork)))
        (if (zero? pid)
          ;; I'm the child
          (with-input-from-port (car pipe2)
            (lambda()
              (with-output-to-port (cdr pipe1) command-thunk)))
          ;; I'm still me :)
          (begin (expect-thunk (cdr pipe2) (car pipe1) pid)
                 (waitpid pid)))))))

(define me
  (lambda(out in pid)
    (call-with-current-continuation
     (lambda(exit)
       (let ((expect-port in)
             (expect-timeout 4)
             (expect-timeout-proc
              (lambda (s)
                (display (string-append "Times up! " s "\n"))
                (kill pid SIGKILL)
                (exit 1)))
                     (expect-eof-proc
                      (lambda (s) (display "Reached tfdes (current-output-port) 
1)
    (execlp "ftp")))
  

(expect-thunks me proc)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]