set /P user_name_=User Name:
(I enter jadill)
...
batch file ends
If I press the up arrow to go back in the history, I find that 'jadill'
is in the list. Now this in itself is not too annoying, but if I
collect several input from the user using 'set /P', all of that text is
in the history.
I've borrowed Herbert's code for getting silent input from a user, so
maybe there is a version that echos the characters to the screen as
they are typed.
Here is something I use for collecting a passwd using Herbert's code,
so if there's a way to modify it to make the characters visible as I
type, that would make my day.
:PASSWORD_PROMPT
set password_command_=%TEMP%\password.com
set password_file_=%TEMP%\passwd
:: This is the ascii representation of a silent character echo program
:: written by Herbert Kleebauer.
echo.hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>%password_command_%
set /P password_=Password: < nul
for /F "usebackq tokens=*" %%i in (`%password_command_% ^| awk -f
password.awk`) do (set password_=%%i)
echo.
if exist %password_command_% (del %password_command_%)
goto :EOF
BTW, Thanks Herbert for your silent input utlility, it comes in very
handy. Makes me wish I knew asm.
Thanks,
John
There are two related approaches that can deal with this:
(1) Run the Batch file in a child shell
Instead of running your Batch file as:
demo.cmd
run it with an explicit single-use CMD shell as:
cmd /c demo.cmd
The command history accumulated during the operation of the Batch
file is lost as the Batch file ends and the single-use shell closes.
(2) Have the Batch file recall itself in a child shell
Typical syntax:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
IF [GOTO:]==[%1] GOTO %2 {Subroutine-Handler}
:: Run the main code
%COMSPEC% /c %0 GOTO: MAIN %1 %2 %3
GOTO EOF {=Subroutine-section-below=}
:MAIN
SET /p MyVar=" Enter user input "
ECHO. User input was %MyVar%
ECHO. First user command-line parameter was %3
ECHO. Second user command-line parameter was %4
:EOF {End-of-file}
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
============Screen capture Windows 2000 simulated in Win95
C:\WORK>demo.bat one two
Enter user input This is the user input
User input was This is the user input
First user command-line parameter was one
Second user command-line parameter was two
C:\WORK>demo.bat one two
============End screen capture
(Last line shows effect of pressing Arrow-up)
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com
>
> Here is something I use for collecting a passwd using Herbert's code,
> so if there's a way to modify it to make the characters visible as I
> type, that would make my day.
Here is an input program where the user can decide whether the
input is hidden or not. If he press <backspace> at the start of the
line, the input is hidden otherwise not.
For W2k/XP:
@echo off
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>inp.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>inp.com
echo supk`LGKsL{OBaswCG@gs@EbBy?x@x@GG{??xOt`B?B_r@mRpEDClpHrHj>>inp.com
echo MLtlH[EEDKi@BB?AzAE`LRsCjnEy?xpH@w?@zAB`LrG_G?0xxxxxxxxxxx>>inp.com
echo Enter your name:|inp.com>nul
for /f %%i in ('inp.com') do set input=%%i
del inp.com
echo.
echo Hello %input%
For Win9x/Me (works also in W2k/XP) you have to use:
echo set input=|inp.com>input.bat
echo.
echo Enter your name:|inp.com>nul
inp.com >>input.bat
call input.bat
del input.bat
del inp.com
echo.
echo Hello %input%
The source code:
@=$100
_30: eor.w r5,r5
_10: move.b #$08,m0
trap #$21
cmp.b #$0d,r0
beq.b _20
move.b r0,buf1
move.b r0,buf2(r5.w)
move.b #$40,m0
move.w #buf1,r1
move.w #1,r2
cmp.b #$08,r0
bne.b _50
move.w #3,r2
subq.w #1,r5
bcc.b _40
inc.w r5
eor.w r2,r2
eor.w r4,r4
_40: dec.w r5
br.b _60
_50: or.w r4,r4
bne.b _60
move.b #'*',buf1
_60: move.w #2,r3
trap #$21
inc.w r5
br.b _10
_20: move.b #$40,m0
move.w #buf2,r1
move.w r5,r2
move.w #1,r3
trap #$21
rts.w
buf1: dc.b $08,$20,$08
buf2:
Perhaps you could use DOSKEY to clear the history - if that was your
purpose.
HTH
...Bill
> There are two related approaches that can deal with this:
> (1) Run the Batch file in a child shell
etc
That is such a good question and a highly useful answer (CMD /C)
that, I'll include an item "128} How to prevent SET /P input from
entering the command history?" with, at lest for now, just the Google
reference your response.
> William Allen
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Thanks to everyone for their responses. This really helps me when
doing DB query/updates batch scripts.
Best regards,
John