中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-25 05:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 重定向的没有得出想要的结果 查看 1,413 回复 3
楼 主 重定向的没有得出想要的结果 发表于 2010-12-24 00:15 ·  中国 河南 新乡 联通
初级用户
★★
积分 96
发帖 83
注册 2009-06-04 00:54
17年会员
UID 146648
性别 男
来自 信阳
状态 离线
下面这段代码得不到想要的结果,但是把>>号前面加上一个空格就可以了,不知道为什么?

echo {>>test.txt
echo if ($2==2) $2=4 >>test.txt
echo else if ($2==1) $2=2 >>test.txt
echo else if ($2==3) $2=5>>test.txt
echo else if ($2==4) $2=3 >>test.txt
echo else $2=1>>test.txt
echo if ($13==1) $13=5>>test.txt
echo else if ($13==2) $13=4>>test.txt
echo else if ($13==3) $13=3>>test.txt
echo else if ($13==4) $13=2>>test.txt
echo else $13=1>>test.txt
echo if ($16==1) $16=5>>test.txt
echo else if ($16==2) $16=4>>test.txt
echo else if ($16==3) $16=3>>test.txt
echo else if ($16==4) $16=2>>test.txt
echo else $16=1>>test.txt
echo if ($19==1) $19=5>>test.txt
echo else if ($19==2) $19=4>>test.txt
echo else if ($19==3) $19=3>>test.txt
echo else if ($19==4) $19=2>>test.txt
echo else $19=1>>test.txt
echo if ($22==1) $22=5>>test.txt
echo else if ($22==2) $22=4>>test.txt
echo else if ($22==3) $22=3>>test.txt
echo else if ($22==4) $22=2>>test.txt
echo else $22=1>>test.txt
echo }>>test.txt
2 发表于 2010-12-24 01:38 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
方法1:
@echo off&setlocal ENABLEDELAYEDEXPANSION
(for /f "usebackq delims=" %%a in ("%~f0") do (
set "a=%%a"
if defined b echo %%a
if "!a:~0,3!"==":标签" set b==
))>test.txt
exit
:标签
{
if ($2==2) $2=4
else if ($2==1) $2=2
else if ($2==3) $2=5
else if ($2==4) $2=3
else $2=1
if ($13==1) $13=5
else if ($13==2) $13=4
else if ($13==3) $13=3
else if ($13==4) $13=2
else $13=1
if ($16==1) $16=5
else if ($16==2) $16=4
else if ($16==3) $16=3
else if ($16==4) $16=2
else $16=1
if ($19==1) $19=5
else if ($19==2) $19=4
else if ($19==3) $19=3
else if ($19==4) $19=2
else $19=1
if ($22==1) $22=5
else if ($22==2) $22=4
else if ($22==3) $22=3
else if ($22==4) $22=2
else $22=1
}
3 发表于 2010-12-24 01:41 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
方法2:
@echo off&setlocal ENABLEDELAYEDEXPANSION
(
echo {
echo if ($2==2) $2=4
echo else if ($2==1) $2=2
echo else if ($2==3) $2=5
echo else if ($2==4) $2=3
echo else $2=1
echo if ($13==1) $13=5
echo else if ($13==2) $13=4
echo else if ($13==3) $13=3
echo else if ($13==4) $13=2
echo else $13=1
echo if ($16==1) $16=5
echo else if ($16==2) $16=4
echo else if ($16==3) $16=3
echo else if ($16==4) $16=2
echo else $16=1
echo if ($19==1) $19=5
echo else if ($19==2) $19=4
echo else if ($19==3) $19=3
echo else if ($19==4) $19=2
echo else $19=1
echo if ($22==1) $22=5
echo else if ($22==2) $22=4
echo else if ($22==3) $22=3
echo else if ($22==4) $22=2
echo else $22=1
echo }
)>test.txt
4 发表于 2010-12-24 01:43 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
方法3:
@echo off
(for /f "delims=" %%a in ('more +3^<"%~f0"') do echo %%a)>test.txt
exit
{
if ($2==2) $2=4
else if ($2==1) $2=2
else if ($2==3) $2=5
else if ($2==4) $2=3
else $2=1
if ($13==1) $13=5
else if ($13==2) $13=4
else if ($13==3) $13=3
else if ($13==4) $13=2
else $13=1
if ($16==1) $16=5
else if ($16==2) $16=4
else if ($16==3) $16=3
else if ($16==4) $16=2
else $16=1
if ($19==1) $19=5
else if ($19==2) $19=4
else if ($19==3) $19=3
else if ($19==4) $19=2
else $19=1
if ($22==1) $22=5
else if ($22==2) $22=4
else if ($22==3) $22=3
else if ($22==4) $22=2
else $22=1
}
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
740011611 +2 2010-12-24 13:43
论坛跳转: