在批处理脚本中,是否有记录的标签长度限制以及出现在标签_之后_的文本?

问题描述 投票:0回答:1

考虑以下标签,其后添加文本以阐明批处理脚本中参数的用途(空格后的任何内容都将被忽略......):

:LineBuilder [1 - main var type 1] [2 - main var type 2] [3 - subvar type] [4 - string to store in 1.3] [5 - Option for giving the length vs needing to calculate it] [6 - var containing Width to pull from] [7 - var containing Blanks to pull from] [8 - Option to add CRLF at the end of string] [9 - Border Option] [10 - Option to justify text 1/left, 2/right, 3/split - right text supplied Arg4, 4/centered, 5/split - left text supplied Arg5] [11 - Left portion of Text if Justy is split [spaces in between text]]

参考这篇SO文章,我知道

Label
本身的最大长度是128个字符。是否还记录了标签after的文本长度可以有多长?如果没有正式记录,或者这个特定问题尚未得到解答,我可能有答案,但想确认它没有在其他地方列出。

不包括冒号(

:
),整行有 511 个字符。之后的字符串长度,包括所有空格(以及将
arg clarifications
Label
本身分隔开的空格)为 500 个字符长。我最终是如何偶然发现这个错误的,我花了一段时间才查明!看起来 CMD 行解释器放弃了将
Label's
字符串数据存储在单个字符串中的尝试,并尝试将最终的
]
解析为命令! (如果您在第一个位置后添加
REM 
,错误将更改为
ext]]
- 正好增加 4 个字符。

']' is not recognized as an internal or external command,
operable program or batch file.

在 Windows 10 中体验这一点。

batch-file windows-10 string-length
1个回答
0
投票

问题的一个例子

@echo off

goto :LineBuilder
REM 12345678
:LineBuilder [1 - main var type 1] [2 - main var type 2] [3 - subvar type] [4 - string to store in 1.3] [5 - Option for giving the length vs needing to calculate it] [6 - var containing Width to pull from] [7 - var containing Blanks to pull from] [8 - Option to add CRLF at the end of string] [9 - Border Option] [10 - Option to justify text 1/left, 2/right, 3/split - right text supplied Arg4, 4/centered, 5/split - left text supplied Arg5] [11 - Left portion of Text if Justy is split [spaces in between text]]

用 LF 行结尾保存它(使用 vscode 你可以在 CRLF 和 LF 之间切换)

然后你得到:

'etween' 不被识别为内部或外部命令、可操作程序或批处理文件。

“未知”命令仅取决于 REM 行中的字符数。

如何解决?

以 CRLF 行结尾保存文件或使用

more defectBatch.bat > workingBatch.bat
© www.soinside.com 2019 - 2024. All rights reserved.