Is it possible to disable command history within a batch file?
After calling a my.bat, the results from calls to things like SET /P
are pushed in to the history. So if I ask my user to enter a machine name, the history now also contains that machine name.
P:>my.bat
P:>SET /P MYENV="myenv prompt:"
myenv prompt:lskdjf
P:>lskdjf
P:>
DOSKEY does not seem to have a way to suspend or disable pushing in to the history stack.
Short answer
doskey /reinstall
This erases the complete history.
A second way could also to start a new cmd.exe instance in your batch, this would only remove the history made by your set/p
statements.
@echo off
if "%~1"==":historySafe" goto :historySafe
cmd /c "%~f0" :historySafe
exit /b
:historySafe
set /p var=Password
echo %var%
exit /b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.