Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 858
hometoast Avatar asked Mar 15 '12 13:03

hometoast


People also ask

What is @echo off in batch script?

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.

How do I delete my Command Prompt history?

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.

Can I see history of commands in cmd?

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.

What does %1 do in batch file?

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.


1 Answers

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
like image 150
jeb Avatar answered Sep 22 '22 10:09

jeb