[Gauche-devel-jp] sys-forkpty (?)の使い方

Back to archive index

Osamu NAKAMURA naka****@hasak*****
2004年 10月 6日 (水) 12:55:51 JST


中村といいます。

Expect(*) みたいなことをしたくて、pexpect(**)をまねて、
まずは、

#!/usr/bin/env gosh
(use gauche.process)
(use gauche.termios)

(let* ((cmd "cat")
       (args (list cmd)))
  (receive
   (pid fd) (sys-forkpty)
   (if (= pid 0) ;; child
       (sys-exec cmd args '((0 . 0) (1 . 1) (2 . 2)))
       )
   ;;
   ;; parent
   (let ((oport (open-output-fd-port fd))
	 (iport (open-input-fd-port fd)))
     (display "123456\n" oport)
     (print (read-block 5 iport))
     )
   )
  )

としてみたのですが、child の 標準入力への書き込み
     (display "123456\n" oport)
ができておらず、
     (print (read-block 5 iport))
で、止まってしまいます。(***)

どこがおかしいのか、コメントいただけませんか?
($ gosh -V
 Gauche scheme interpreter, version 0.8.1 [euc-jp])


(*)Expect
"Expect is a tool for automating interactive applications
 such as telnet, ,,"
http://expect.nist.gov/

(**)pexpect
Python による expect の実装。
http://pexpect.sourceforge.net/

scsh や guile には expect.scm があるようでしたが、
修行がたらず、python の方がまだ読みやすく、、^^;;;

(***)
ちなみに、python では、
#!/usr/bin/env python
# -*- encodings: japanese.euc_jp -*-
import os, pty

command="cat"
args=[command]
pid, child_fd = pty.fork()

if pid == 0: os.execvp(command, args)

os.write(child_fd, "123456\n")
s = os.read(child_fd, 100)

print s
で、動いたりしてます。

-- 



Gauche-devel-jp メーリングリストの案内
Back to archive index