日期:2014-05-17  浏览次数:21644 次

bat中获取用户输入,如何做到不回显
获取用户输入时,如果是输入密码,则不回显,如下:
SET password=MANAGER
SET /P password="Password [%password%]: "

请问,如何做到呢?
------解决方案--------------------
a.bat:
password.exe
FOR /F %%p IN (password.txt) DO set PASSWORD=%%p
del password.txt >nul
if "%PASSWORD%"=="" goto e
if "%PASSWORD%"=="" goto e
rem 做需要%PASSWORD%的一系列工作
:e
set PASSWORD=

password.c
#include <conio.h>
#include <stdio.h>
char pw[40];
int i,ch;
FILE *f;
void main() {
    cprintf("\r\nPassword:");
    i=0;pw[i]=0;
    while (1) {
        ch=getch();
        if (ch==13 
------解决方案--------------------
 i>=39) break;
        switch (ch) {
        case 27:
            cprintf("\rPassword: %40s"," ");
            cprintf("\rPassword: ");
            i=0;pw[i]=0;
            break;
        case 8:
            if (i>0) {
                i--;
                pw[i]=0;
                cprintf("\b \b");
            }
            break;
        default:
            pw[i]=ch;
            i++;
            pw[i]=0;
            cprintf("*");
            break;
        }
    }
    cprintf("\r\n");
    f=fopen("password.txt","w");
    fprintf(f,"%s\n",pw);
    fclose(f);
}

------解决方案--------------------
最开始:
@echo off