ºìÁªLinuxÃÅ»§
Linux°ïÖú

"½ûÓÃ"LinuxÖÕ¶ËÊä³ö»ØÏÔ

·¢²¼Ê±¼ä:2008-02-21 00:39:10À´Ô´:ºìÁª×÷Õß:dwillin
Termios½á¹¹ÊÇÔÚPOSIX¹æ·¶Öж¨ÒåµÄÒ»¸ö±ê×¼½Ó¿Ú,ͨ¹ýÉèÖÃtermiosÀàÐ͵ÄÊý¾Ý½á¹¹ÖÐÖµ¼°Ïà¹Øº¯Êýµ÷Óñã¿ÉÒÔ¶ÔÖն˽ӿڽøÐпØÖÆ¡£

¿ØÖÆÖն˵ÄÊä³ö»ØÏÔÖ÷ÒªÓõ½"±¾µØģʽ"ÖпÉÓõÄc_lflagµÄºêECHO,ECHOºê¶¨ÒåΪ:ÆôÓÃÊäÈë×Ö·ûµÄ±¾µØ»ØÏÔ¹¦ÄÜ

´Ë¹¦ÄÜ×î³£¼ûµÄÓ¦ÓÃĪ¹ýÓÚ¿ØÖÆÊäÈëÃÜÂëµÄ»ØÏÔ,Èçͨ¹ýsudo /etc/**»ñÈ¡¹ÜÀíȨÏÞ»òÖն˵ǼMySQLʱÊäÈëµÄÃÜÂëÊDz»»áÏÔʾ³öÀ´µÄ¡£

¶øtermios½á¹¹µÄ¶¨Òå°üº¬ÔÚtermios.hÍ·ÎļþÖÐ,Ö±½Ó¿´´úÂë:

ÒýÓÃ:
#include
#include
#include

#define PASSWORD_LEN 12

int main(){
struct termios initialrsettings, newrsettings;
char password[PASSWORD_LEN + 1];
tcgetattr(fileno(stdin),&initialrsettings); #»ñÈ¡termios½á¹¹²¢±£´æ
newrsettings = initialrsettings;
newrsettings.c_lflag &= ~ECHO; #Çå³ý±äÁ¿c_lflagÖÐÓÉECHO¶¨ÒåµÄ±ÈÌØ
printf("Please Enter Password:");
if( tcsetattr(fileno(stdin),TCSAFLUSH,&newrsettings) != 0 ){
fprintf(stderr,"Could not set arrributes\n");
}else{
fgets(password,PASSWORD_LEN,stdin);
tcsetattr(fileno(stdin),TCSANOW,&initialrsettings); #»¹Ô­Ö®Ç°µÄtermios½á¹¹
fprintf(stdout,"\nYou entered %s as the password\n",password);
}
exit(0);
}


×îºó±àÒë¡¢ÔËÐÐÖ®,´ïµ½Ô¤ÆÚÄ¿µÄ~

²»Í¬Linux·¢ÐаæÐèÒª°üº¬µÄÍ·Îļþ¿ÉÄÜ´æÔÚϸ΢µÄ²îÒì,ÒÔÏÂÊÇÎÒÖ÷»úµÄÐÅÏ¢:

ÒýÓÃ:
Hardware:i686
OS:Linux (ubuntu desktop 7.10)
Release:2.6.22-14-generic
Version:#1 SMP Tue Feb 12 07:42:25 UTC 2008
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ