From: Ian Macdonald Date: 2002-05-02T15:04:10+09:00 Subject: Re: How do I use IO.ioctl(arg1, arg2..) On Thu 02 May 2002 at 14:39:11 +0900, Bob Gustafson wrote: > The pickaxe book is a bit sparse on documentation for using the method > ioctl for IO class objects. > > Is there a guide somewhere? > > I want to turn echo on and off on an IO object. > > I guess I could use system("stty -F /dev/ttyS1 echo"), if I knew which > physical device was inside a particular IO object. You can also use the termios module for this, although documentation is rather sparse there, too. Here's how you would turn echo on/off for $stdin: def echo(on) term = Termios::getattr($stdin) if on term.c_lflag |= Termios::ECHO else # off term.c_lflag &= ~Termios::ECHO end Termios::setattr($stdin, Termios::TCSANOW, term) end def get_passwd begin echo(false) print "Password: " $stdin.gets.chomp ensure echo(true) print "\n" end end Ian -- Ian Macdonald | A good plan today is better than a perfect ian@caliban.org | plan tomorrow. -- Patton | | |