中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 14:52
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Help]Often when writing batch processing, there is "There should not be goto here at this time"
Printable Version  2,290 / 2
Floor1 doslike Posted 2011-01-15 18:22
版主 Posts 285 Credits 326 From 黑龙江省
Often such problems occur. Why do they occur? And how to solve them?
Floor2 Hanyeguxing Posted 2011-01-15 22:35
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
1. A single `goto` alone will not cause such a problem.

2. `goto` combined with other commands. Of course, it is most combined with `if`.

The first type, character comparison: `if %a%==1 goto b`
When `%a%` is empty, an error is returned: at this time, `goto` should not be present.
Solution: Add quotes `if "%a%"=="1" goto b`

The second type, numerical comparison: `if %a% lss 1 goto b`
Because numerical comparison needs to be performed, so quotes cannot be added to avoid the situation where `%a%` is empty.
Solution 1: Handle the situation where `%a%` is empty alone before this.
Solution 2: Use delayed variables, for example `if !a! lss 1 goto b`

[ Last edited by Hanyeguxing on 2011-1-15 at 22:36 ]
Floor3 726842270 Posted 2011-01-17 02:33
初级用户 Posts 43 Credits 65 From 吉林省长春市
So you mean that CMD's handling of spaces is between "%variable%" and "!variable!", right? (PS: I guess it's also after %%I in FOR, otherwise how could you delete blank lines)
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023