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.
batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.
4] Clear command prompt history using Alt+F7 The command history is cleared automatically every time you close it and start the command prompt again. To clear the command history, you can also use Alt+F7 keyboard shortcut. Alt+F7 works for Command Prompt and PowerShell as well.
Open CMD from the Start Menu and type “doskey /History”. As you typed, all the commands which you typed latterly are shown to you in your CMD window. Use Up and Down arrow to select the command. Or you can also Copy and Paste the commands from the history that has appeared on your screen, within the CMD window.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With