运行时出现批处理错误 [英] Get A Batch Error When Running
问题描述
运行此命令后,关闭前我只能看到几行,例如_和黑色批处理文件屏幕关闭.
When I run this all I can see before it closes are a few lines e.g _ and a black batch file screen closing.
推荐答案
|
字符称为管道.它分隔命令,将一个命令的输出推入另一个命令的输入.由于它们在批处理脚本中具有特殊的含义,因此,您不能只回显它们而不必用尖号将其转义,或将它们设置为变量并延迟扩展进行检索.
The |
character is called a pipe. It separates commands, pushing the output of one command into the input of another. Because they have special meaning in batch scripts, you can't just echo them without escaping them with a caret, or setting them to a variable and retrieving with delayed expansion.
这是一个转义的简单示例:
Here's a simple example of escaping:
@echo off
setlocal
echo _______ _____ _______ _______
echo \ / ^| ^| / \ / \ ^|\ /^| ^|
echo \ / ^| ^| ^| ^| ^| ^| \ / ^| ^|
echo \ / ^|_______ ^| ^| ^| ^| ^| \/ ^| ^|_______
echo \ /\ / ^| ^| ^| ^| ^| ^| ^| ^|
echo \ / \ / ^| ^| ^| ^| ^| ^| ^| ^|
echo \/ \/ ^|_______ ^|______ \_____/ \_______/ ^| ^| ^|_______
pause
这是延迟扩展的示例:
@echo off
setlocal enabledelayedexpansion
set "I=|"
echo _______ _____ _______ _______
echo \ / !I! !I! / \ / \ !I!\ /!I! !I!
echo \ / !I! !I! !I! !I! !I! !I! \ / !I! !I!
echo \ / !I!_______ !I! !I! !I! !I! !I! \/ !I! !I!_______
echo \ /\ / !I! !I! !I! !I! !I! !I! !I! !I!
echo \ / \ / !I! !I! !I! !I! !I! !I! !I! !I!
echo \/ \/ !I!_______ !I!______ \_____/ \_______/ !I! !I! !I!_______
pause
作为高级练习,如果您想使figlet"WELCOME"文本在源代码中保持可读性,可以使用批处理脚本heredoc :
As an advanced exercise, if you'd like to keep the figlet "WELCOME" text readable within the source code, you could employ a batch script heredoc:
@echo off
setlocal
call :heredoc welcome && goto end_welcome
_______ _____ _______ _______
\ / | | / \ / \ |\ /| |
\ / | | | | | | \ / | |
\ / |_______ | | | | | \/ | |_______
\ /\ / | | | | | | | |
\ / \ / | | | | | | | |
\/ \/ |_______ |______ \_____/ \_______/ | | |_______
:end_welcome
pause
goto :EOF
rem // https://stackoverflow.com/a/15032476/1683264
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
set "line=%%A" && set "line=!line:*:=!"
if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
if "!line:~0,13!"=="call :heredoc" (
for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
if #%%i==#%1 (
for /f "tokens=2 delims=&" %%I in ("!line!") do (
for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
)
)
)
)
)
goto :EOF
顺便说一句,您应该记住命令提示符窗口默认为80列.您所拥有的屏幕截图看起来对于典型的控制台窗口来说太宽了.
By the way, you should keep in mind that command prompt windows are 80 columns by default. What you have screenshot looks like it'll be too wide for a typical console window.
这篇关于运行时出现批处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!