|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『楼 主』:
如何获得命令执行后返回的值
使用 LLM 解释/回答一下
如何获得命令执行后返回的值?
比如,有个文件,名为a.txt,内容是:
1
用type命令:
C:\>TYPE A.TXT
C:\>1
在批处理中如何获得这个type命令执行后显示的1,并把它加1后保存入a.txt中,即a.txt的内容就变为2了
C:\>TYPE A.TXT
C:\>2
环境要求:DOS6.22或DOS7.1
谢谢!
How to get the value returned after a command is executed?
For example, there is a file named a.txt with content:
1
Using the type command:
C:\>TYPE A.TXT
C:\>1
How to get the 1 displayed after the type command is executed in a batch script and add 1 to it, then save it into a.txt, that is, the content of a.txt becomes 2.
C:\>TYPE A.TXT
C:\>2
Environment requirements: DOS6.22 or DOS7.1
Thank you!
|
|
2008-1-2 12:55 |
|
|
everdos
初级用户
 
积分 52
发帖 21
注册 2008-1-1
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f %%a in (a.txt) do set /a pp=%%a+1
echo %pp% > a.txt
for /f %%a in (a.txt) do set /a pp=%%a+1
echo %pp% > a.txt
|
|
2008-1-3 01:27 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
|
2008-1-3 09:13 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
test1.bat
call test2.bat 1 2 3 4 5 6 7 8 9
test2.bat
:start1
if "%1"=="" goto end
find "%1" A.TXT
if errorlevel 0 goto xxx
shift
goto start1
:xxx
shift
echo %1>A.TXT
:end
给个思路,代码未测试
test1.bat
call test2.bat 1 2 3 4 5 6 7 8 9
test2.bat
:start1
if "%1"=="" goto end
find "%1" A.TXT
if errorlevel 0 goto xxx
shift
goto start1
:xxx
shift
echo %1>A.TXT
:end
Give an idea, the code is not tested
|

第一高手 第二高手
我的小站
 |
|
2008-1-3 10:21 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
测试代码可以了,只是执行结果echo %1>A.TXT 其实是echo 2>A.TXT,所以要加转定义符号echo ^%1>A.TXT
The test code is okay. It's just that the execution result echo %1>A.TXT is actually echo 2>A.TXT, so we need to add the escape definition symbol echo ^%1>A.TXT
|

第一高手 第二高手
我的小站
 |
|
2008-1-3 11:00 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
加强判断errorlevel返回值
test1.bat
@echo off
call test2.bat 1 2 3 4 5 6 7 8 9
test2.bat
:start1
if "%1"=="" goto end
find "%1" A.TXT>nul
if not errorlevel 1 if errorlevel 0 goto xxx
shift
goto start1
goto end
:xxx
shift
echo ^%1>A.TXT
:end
Strengthen judgment of errorlevel return value
test1.bat
@echo off
call test2.bat 1 2 3 4 5 6 7 8 9
test2.bat
:start1
if "%1"=="" goto end
find "%1" A.TXT>nul
if not errorlevel 1 if errorlevel 0 goto xxx
shift
goto start1
goto end
:xxx
shift
echo ^%1>A.TXT
:end
|

第一高手 第二高手
我的小站
 |
|
2008-1-3 11:40 |
|
|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
测试时不知哪里出了问题?有两个问题:
(1)出现“一般性错误读驱动器F”的提示
(2)第二次运行test1.bat后的结果还是2,而没有变成3
请指教。
下面是运行的结果
E:\>TYPE A.TXT
1
E:\>TEST1
一般性错误读驱动器F
A:放弃,R:重试,F:失败?a
E:\>type a.txt
2
e:\>test1
一般性错误读驱动器F
A:放弃,R:重试,F:失败?a
E:\>type a.txt
2
不知如何贴图,只好敲上去了
What went wrong during the test? There are two issues:
(1) A prompt "General error reading drive F" appears.
(2) After running test1.bat for the second time, the result is still 2 instead of becoming 3.
Please give guidance.
Here are the running results
E:\>TYPE A.TXT
1
E:\>TEST1
General error reading drive F
A: Abort, R: Retry, F: Fail? a
E:\>type a.txt
2
e:\>test1
General error reading drive F
A: Abort, R: Retry, F: Fail? a
E:\>type a.txt
2
I don't know how to attach pictures, so I have to type them out
|
|
2008-1-4 10:26 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
出现一般性错误读驱动器F和代码无关,代码部分没尝试要访问F盘
纯DOS代码不稳定很容易出现一般性错误读驱动器F这样的错误,请检查你的批处理代码是否有访问F盘部分,或者不要加载光驱驱动。
另外6楼的代码你可以在XP下测试,代码纯DOS和XP通用的,只是纯DOS要把echo ^%1>A.TXT改为echo %1>A.TXT
Last edited by fastslz on 2008-1-4 at 11:04 AM ]
General errors occur when reading drive F, which has nothing to do with the code. The code part did not attempt to access drive F.
The pure DOS code is unstable and easily causes errors like "general error reading drive F". Please check if your batch code has parts that access drive F, or do not load the CD-ROM driver.
In addition, you can test the code on floor 6 under XP. The code is universal for pure DOS and XP. Just change echo ^%1>A.TXT to echo %1>A.TXT in pure DOS.
Last edited by fastslz on 2008-1-4 at 11:04 AM ]
|

第一高手 第二高手
我的小站
 |
|
2008-1-4 10:48 |
|
|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我是按6楼的代码进行测试的,一点都没变
I tested according to the code on floor 6, and didn't change it at all
|
|
2008-1-4 11:56 |
|
|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
(1)在XP下测试没有问题,能够替加,但到9后就不能再加了。
(2)在DOS7.1下测试就出现“一般性错误读驱动器F”。而且不会替加
(1) Tested under XP with no issues, can add, but can't add after reaching 9.
(2) Tested under DOS 7.1 and got "General error reading drive F" and won't add.
|
|
2008-1-4 12:05 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
我猜测分析下是什么原因吧
F应该是你的光盘盘符,你启动的DOS下没有find.com外部命令,而Path变量里有%CDROM%或F:\.....,这个时候DOS就尝试读取光盘下目录寻找find.com,所以出现一般性错误读驱动器F,纯DOS下就这样没个细节都不能错。
最后再强调下纯DOS要把6楼的代码echo ^%1>A.TXT改为echo %1>A.TXT
I will guess and analyze what the reason might be.
F should be your CD - ROM drive letter. The DOS you booted into doesn't have the external command find.com, and the Path variable has %CDROM% or F:\..... At this time, DOS tries to read the directory under the CD - ROM to find find.com, so a general error occurs when reading drive F. That's how it is in pure DOS; no detail can be wrong.
Finally, emphasize again In pure DOS, change the code echo ^%1>A.TXT in building 6 to echo %1>A.TXT
|

第一高手 第二高手
我的小站
 |
|
2008-1-4 12:10 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
(1)在XP下测试没有问题,能够替加,但到9后就不能再加了。
只能是9呢也没办法,是find.com限制,因为10里面包含1,如果用sed就没有这个限制了
(1) Tested under XP with no problem, can be added, but cannot be added after 9.
Only 9, there is no way, it is the limitation of find.com, because 10 contains 1, if you use sed, there is no such limitation
|

第一高手 第二高手
我的小站
 |
|
2008-1-4 12:23 |
|
|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
谢谢! 真的是没有find.exe命令。加上后就OK了!
在dos7.1下就没有办法突破10以内的限制吗?
Thanks! It's really that there is no find.exe command. After adding it, it's OK!
Is there really no way to break through the limit within 10 under dos7.1?
|
|
2008-1-4 13:02 |
|
|
kavenlee72
中级用户
  
积分 369
发帖 87
注册 2003-9-14
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
在新DOS时代网站的DOS使用中有介绍count,加法计算的工具,但不知哪里有下载?论坛里没找到
In the DOS usage introduction on the New DOS Era website, there is an introduction to count, a tool for addition calculations, but I don't know where to download it. I didn't find it in the forum.
|
|
2008-1-4 13:11 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
@echo off
call test2.bat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
:start1
if "%1"=="" goto end
sed -n "/%1/p" A.TXT>nul
if not errorlevel 1 if errorlevel 0 goto xxx
shift
goto start1
goto end
:xxx
shift
echo %1>A.TXT
:end
sed纯DOS版我的google论坛上有,点我签名连接
sed用法 http://sed.sourceforge.net/sed1line_zh-CN.html
@echo off
call test2.bat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
:start1
if "%1"=="" goto end
sed -n "/%1/p" A.TXT>nul
if not errorlevel 1 if errorlevel 0 goto xxx
shift
goto start1
:end
:xxx
shift
echo %1>A.TXT
:end
The pure DOS version of sed is available on my Google forum. Click my signature link.
Sed usage http://sed.sourceforge.net/sed1line_zh-CN.html
|

第一高手 第二高手
我的小站
 |
|
2008-1-4 13:22 |
|