简体   繁体   中英

Disable command history in a windows batch file

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

While in the Windows command line, press the F7 key to view a history of all the commands that have been entered in that window. Below is a picture of what the Windows command line history box will look like when open.

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM