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

¡°½ûÓá±LinuxÖÕ¶ËÊä³öµÄ»ØÏÔ

·¢²¼Ê±¼ä:2008-03-25 00:43:44À´Ô´:ºìÁª×÷Õß:DrearsCma
Termios½á¹¹ÊÇÔÚPOSIX¹æ·¶Öж¨ÒåµÄÒ»¸ö±ê×¼½Ó¿Ú£¬Í¨¹ýÉèÖÃtermiosÀàÐ͵ÄÊý¾Ý½á¹¹ÖÐÖµ¼°Ïà¹Øº¯Êýµ÷Óñã¿ÉÒÔ¶ÔÖն˽ӿڽøÐпØÖÆ¡£¿ØÖÆÖն˵ÄÊä³ö»ØÏÔÖ÷ÒªÓõ½"±¾µØģʽ"ÖпÉÓõÄc_lflagµÄºêECHO,ECHOºê¶¨ÒåΪ:ÆôÓÃÊäÈë×Ö·ûµÄ±¾µØ»ØÏÔ¹¦ÄÜ

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

¶øtermios½á¹¹µÄ¶¨Òå°üº¬ÔÚtermios.hÍ·ÎļþÖÐ,Ö±½Ó¿´´úÂë:[code]#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);
}[/code]×îºó±àÒë¡¢ÔËÐÐÖ®£¬´ïµ½Ô¤ÆÚÄ¿µÄ

²»Í¬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
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. Linux85fan ÓÚ 2008-03-26 22:23:49·¢±í:

    ÕâЩ¶«Î÷¡£¡£¡£¡£¡£¡£¡£¾Í²»ÓÃ˵ÁËÂï