From: nobu.nokada@... Date: 2004-04-15T10:24:17+09:00 Subject: Re: ruby pty/expect help Hi, At Thu, 15 Apr 2004 01:09:20 +0900, Ara.T.Howard wrote in [ruby-talk:97152]: > ~/eg/ruby > ruby ssh-keygen.rb > Generating public/private rsa key pair. > Enter file in which to save the key (/home/ahoward/.ssh/id_rsa): id_rsa > Enter passphrase (empty for no passphrase): > Enter same passphrase again: ssh-keygen.rb:22:in `read': Input/output error - /dev/pts/19 (Errno::EIO) > from ssh-keygen.rb:22 > from ssh-keygen.rb:8:in `spawn' > from ssh-keygen.rb:8 > > > without the read it generates the expected output, but no id_rsa file is > produced and no error is given... doesn't the call to IO.expect do the reading > anyhow? also, the example in ext/pty/example_expect.rb doesn't seem to do any > reading either? Because the watchdog thread created by PTY.spawn signals the main thread when child exits, and read(2) is interrupted. In such case, however, I feel that IO#read should return already read data, if exists. BTW, you don't need PTY at all to generate ssh key automatically. $ rm -f id_rsa{,.pub} $ ssh-keygen -t rsa -N "" -f id_rsa Generating public/private rsa key pair. Your identification has been saved in id_rsa. Your public key has been saved in id_rsa.pub. The key fingerprint is: 42:1f:bc:76:60:45:a1:2b:fd:cc:4c:a2:3a:0c:87:c6 nobu@sharui.nakada.niregi.kanuma.tochigi.jp Index: io.c =================================================================== RCS file: /cvs/ruby/src/ruby/io.c,v retrieving revision 1.271 diff -u -2 -p -r1.271 io.c --- io.c 14 Apr 2004 04:06:25 -0000 1.271 +++ io.c 15 Apr 2004 01:18:27 -0000 @@ -953,10 +953,9 @@ rb_io_fread(ptr, len, f) case EWOULDBLOCK: #endif - if (len - n >= 0) { + if (len > n) { clearerr(f); - return len - n; } } - return 0; + if (len == n) return 0; } *ptr = '\0'; -- Nobu Nakada