Some shells echo the commands that you send to them, and the echoed
commands appear in the output buffer. In particular, the default
shells, command.com and cmd.exe, have this behavior.
To prevent echoed commands from being printed, you can place the following in your init file:
(defun my-comint-init ()
(setq comint-process-echoes t))
(add-hook 'comint-mode-hook 'my-comint-init)
If shell-mode still is not stripping echoed commands, then
you’ll have to explicitly tell the shell to not echo commands. You can
do this by setting the explicit-SHELL-args variable
appropriately; where SHELL is the value of your SHELL
environment variable (do a M-: (getenv "SHELL") to see what it
is currently set to). Assuming that you are on NT and that your
SHELL environment variable is set to cmd.exe,
then placing the following in your init file will tell
cmd.exe to not echo commands:
(setq explicit-cmd.exe-args '("/q"))
The comint package will use the value of this variable as an argument
to cmd.exe every time it starts up a new shell; the
/q is the argument to cmd.exe that stops the
echoing (invoking ‘cmd /?’ in a shell will show you all of the
command line arguments to cmd.exe).
Note that this variable is case sensitive; if the value of your
SHELL environment variable is CMD.EXE instead, then
this variable needs to be named explicit-CMD.EXE-args instead.