China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-19 23:43
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] setlocal EnableDelayedExpansion and "!" View 9,325 Replies 25
Original Poster Posted 2006-06-11 15:31 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Today on duty, really bored. CS was beaten by others, QQ has no one to chat with. Want to write a bat but can't figure it out. Fainted on the front line.
Hope brothers can give pointers.

setlocal EnableDelayedExpansion
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" cover.ps') do (

if !m!










If using set and then echo, then the % in the text will be replaced.
If using call, and not enabling variable delay, when passing %%m of for to call, the same thing will be lost.
So I still enabled variable delay, and the result is that the! are all gone. Hope experts can give advice.

[ Last edited by willsort on 2006-6-20 at 11:37 ]
Floor 2 Posted 2006-06-12 23:48 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Since variable delay is used, why still use %m% to reference? It should be changed to !m! instead.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wenqs27 +1 2009-01-17 15:41
Floor 3 Posted 2006-06-13 13:31 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I tested the following code, it has already added 1. What exactly do you want it to become?

Specifically, whether there is a problem with the code, because the function you want to implement is unclear, I didn't look closely, but at least it can add 1, otherwise you can give it a try.


@echo off
setlocal EnableDelayedExpansion
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" cover.ps') do (

if %m%






Floor 4 Posted 2006-06-17 10:29 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Hope the experts can give an idea! Thanks
Floor 5 Posted 2006-06-17 12:17 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
setlocal EnableDelayedExpansion
set m=0
for /f "tokens=* delims=" %%m in ('findstr /v /C:"730 730" cover.ps') do (
if "!m!"=="686" (pause) else echo %%m >>cover3.txt
set /a m=!m!+1
)
pause
exit
I don't know what effect the original poster wants. There is nothing wrong with this batch script
Floor 6 Posted 2006-06-17 13:28 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
This is this meaning. If once there is an exclamation mark in cover.ps, because the variable delay is enabled, this exclamation mark cannot be echoed into the new file.
Floor 7 Posted 2006-06-17 15:09 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
@echo off
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" 2.txt') do (
setlocal EnableDelayedExpansion
set /a m=!m!+1
if "!m!"=="686" (pause) else setlocal DISABLEDELAYEDEXPANSION&&echo %%m>>test.txt
)
echo %m%

The method is a bit crude, but this issue needs to be considered. The original poster can try this first
Floor 8 Posted 2006-06-17 15:17 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
.....
F:\Print\blogcn订单\用户单\163>
setlocal EnableDelayedExpansion
set /a m=!m!+1
if "!m!" == "686" (pause) els
192.168.0.158\\BlogPrinting\\Sy
e\\CoverPage_BG.jpg) 1>>test.tx
)
Exceeded the maximum setlocal recursion depth.
Exceeded the maximum setlocal recursion depth.

This is the run record
Floor 9 Posted 2006-06-17 15:18 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
And the exclamation mark is still gone
Floor 10 Posted 2006-06-17 15:20 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
It seems that this problem occurs with repeated calls, but it's okay if the number of lines is small. I just tested it and didn't expect this problem. I'm thinking about it.
Floor 11 Posted 2006-06-17 15:21 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
What system are you using? I tested with Windows 2000
Floor 12 Posted 2006-06-17 15:22 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline

───────────────── Moderation Record ─────────────────
Performed by: Will Sort
Operation: Move Topic: From DOS Troubleshooting & Discussion (Help Desk)
Explanation: According to topic content classification, it is more suitable to be posted in this forum section
Punishment: Deduct 6 points of rewards for posting this topic, and deduct 2 points of points for forum section violations
───────────────── Moderation Record ─────────────────


Re kcdsw:

First of all, set/a has an independent variable recognition mechanism, and there is no need to use the form of!m! for delayed variable expansion. You can directly use set /a m+=1. However, using set /a m=%m%+1 in building 3 will instead have the problem of not being able to continuously increase because it always uses the initialized variable.

Secondly, regarding the problem of! being escaped in the text, the solution is still to turn off variable delay and use call, but when passing %%m, it is no longer using command line parameters, but using environment variables. As follows:


@echo off
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" cover.ps') do (
set line=%%m
call :Output
set /a m+=1
)
pause
exit

:Output
if "%m%" == "686" (pause) else (echo %line% >>cover3.txt)
goto :eof


[ Last edited by willsort on 2006-6-17 at 15:24 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 13 Posted 2006-06-17 15:33 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Oh, I see......
Floor 14 Posted 2006-06-17 15:38 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Tears shed tears and.... continue posting

I uploaded it

The purpose is to have the line containing 730 730, and recalculate its width through the pixel data of the next line
ps: 730 730 are the length and width values, but the original photo is not a square, so the length and width ratio is wrong. I want to use this to change it to the correct one, but I accidentally lost the exclamation mark

My environment is xp sp2 (oem genuine version)

[ Last edited by kcdsw on 2006-6-17 at 15:44 ]
Attachments
163.rar (14.39 KiB, Credits to download 1 pts, Downloads: 52)
Floor 15 Posted 2006-06-17 15:51 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
F:\Print\blogcn订单\用户单\163>if "17" == "day" call setp
The syntax error is: There should not be << here.

F:\Print\blogcn订单\用户单\163>echo lineto/num num 1 sub def num 0 le{exit}if}lo
op}bd/EmptyDict <<>> def >>cover3.txt
Forum Jump: