简体   繁体   English

Windows批处理作业如何在回显关闭时回显命令

[英]Windows batch job how to echo a command when echo is off

I have searched and searched for this and I can't find the answer. 我已经搜索了此内容,却找不到答案。 Maybe it's not possible. 也许不可能。 I want to do "echo off" for my whole batch job, BUT i want certain lines to echo. 我想为整个批处理工作“回音”,但是我希望某些行回音。

I know I could put an @ in front of every line and just leave the @ off any lines I DO want to echo. 我知道我可以在每行前面加一个@,然后将@保留在我想回显的任何行之外。

But is there a way to do: 但是有办法吗:

echo off
call setver
if not exist todir md todir
copy myfile.exe todir

I want nothing to echo EXCEPT the "copy" statement... 除了“复制”语句外,我什么也不想回声...

@echo off
call setver
if not exist todir md todir
ECHO ON
copy myfile.exe todir
@ECHO OFF

should do what you want, IIUC. 应该做你想做的,IIUC。

and for the inevitable follow-up, "how do you echo the word "on"` 对于不可避免的后续行动,“您如何回应“ on”一词?

echo(on

where ( may be any of the usual crew like . etc. 其中(可以是任何常用的船员等.

You could also echo the command itself before executing it. 您也可以在执行命令之前回显命令本身。

@echo off
call setver
if not exist todir md todir
echo copy myfile.exe todir
copy myfile.exe todir

As it can be seen, the command to show visible is just duplicated in file and echo is put before. 可以看出,显示可见的命令只是复制到文件中,而echo放在前面。 That works also with environment variables referenced on line of the command. 这也适用于在命令行中引用的环境变量。

Care must be taken only on a command which contains a redirection as the redirecting angle bracket(s) must be escaped with ^ to output the angle bracket instead of redirecting the message. 必须仅对包含重定向的命令小心,因为重定向尖括号必须用^进行转义以输出尖括号而不是重定向消息。 Example: 例:

@echo off
echo set ^>"%TEMP%\AllVariables.txt"
set >"%TEMP%\AllVariables.txt"
del "%TEMP%\AllVariables.txt"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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