|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
 『楼 主』:
[已结]setlocal EnableDelayedExpansion 与 "!"
使用 LLM 解释/回答一下
今天值班,实在无聊 cs被人菜,qq没人聊.想写bat也没绕过来 昏到在阵地上了
还望兄弟们指点
setlocal EnableDelayedExpansion
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" cover.ps') do (
if !m!
如果使用set 再echo 那么文本中的%会被替换掉.
如果使用call,而不启用变量延迟,将for的%%m传递给call的时候同样会丢失东西
所以我还是启用了变量延迟,所造成的结果就是! 都不见了 希望高手赐教
Last edited by willsort on 2006-6-20 at 11:37 ]
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 ]
|
|
2006-6-11 15:31 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
既然起用了变量延迟,为什么还要用%m%来引用呢?应该该成!m!才对啊。
Since variable delay is used, why still use %m% to reference? It should be changed to !m! instead.
|
|
2006-6-12 23:48 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
我测试了一下下面的代码,它已经加了1了啊,你到底想让它变成多少呢?
具体的代码有没有问题,因为你想要实现的功能不明了,我没去细看,但是至少是能够加1的,要不然你试试吧。
@echo off
setlocal EnableDelayedExpansion
set m=0
for /f "tokens=*" %%m in ('findstr /v /C:"730 730" cover.ps') do (
if %m%
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%
|
|
2006-6-13 13:31 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
希望高手能给个思路! 谢谢
Hope the experts can give an idea! Thanks
|
|
2006-6-17 10:29 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
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
不知道楼主想要什么样的效果,这个批处理没有什么错误的地方
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
|
|
2006-6-17 12:17 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
是这个意思 如果一旦cover.ps中 含有感叹号的时候
会因为启用变量延迟 而造成这个感叹号不能被echo 到新文件中去
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.
|
|
2006-6-17 13:28 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
@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%
方法有点糙,不过这个问题有待考虑考虑了,楼主试试这个先
@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
|
|
2006-6-17 15:09 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
.....
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
)
已经达到最大的 setlocal 递归层。
已经达到最大的 setlocal 递归层。
这是运行记录
.....
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
|
|
2006-6-17 15:17 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
而且感叹号 还是不见了
And the exclamation mark is still gone
|
|
2006-6-17 15:18 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
看来重复调用会出现这个问题,不过行数如果少的话是可以的,我刚刚已经测试了,没有想到这个问题,在考虑考虑
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.
|
|
2006-6-17 15:20 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
你的什么系统啊?我测试的是2000
What system are you using? I tested with Windows 2000
|
|
2006-6-17 15:21 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
───────────────── 版务记录 ─────────────────
执行:Will Sort
操作:移动主题:自 DOS疑難解答 & 問題討論(解答室)
说明:依照主题内容分类,更适合于发表在此版区
处罚:扣除因发表该主题而奖励的6点积分,版区违规惩罚性扣除2点积分
───────────────── 版务记录 ─────────────────
Re kcdsw:
首先,set/a有一套独立的变量识别机制,不需要使用!m!的形式延迟变量扩展,直接使用set /a m+=1 即可。而使用3楼中的 set /a m=%m%+1 反而会因为始终饮用初始化的变量,而出现无法持续递增的问题。
其次,关于文本中的!被转义的问题,解决办法仍然是关闭变量延迟并使用call,只是传递%%m时不再使用命令行参数,而是使用环境变量。如下:
@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 ]
───────────────── 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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-17 15:22 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
|
2006-6-17 15:33 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
泪流而....继续发帖
我传上来了
目的是在含有 730 730 这一行 通过它下一行的象素数据 重新计算它的宽度
ps: 730 730 为长宽值 但是原照片不是正方形 所以长宽比例错了 我想借用这个改成正确的 不想却出了篓子 把感叹号丢了
我的环境是 xp sp2 (oem正版)
Last edited by kcdsw on 2006-6-17 at 15:44 ]
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 ]
附件
1: 163.rar (2006-6-17 15:39, 14.39 KiB, 下载附件所需积分 1 点
,下载次数: 52)
|
|
2006-6-17 15:38 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
F:\Print\blogcn订单\用户单\163>if "17" == "day" call setp
此时不应有 <<。
F:\Print\blogcn订单\用户单\163>echo lineto/num num 1 sub def num 0 le{exit}if}lo
op}bd/EmptyDict <<>> def >>cover3.txt
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
|
|
2006-6-17 15:51 |
|