![]() |
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-13 22:58 |
47,812 topics / 349,916 posts / today 0 new / 48,268 members |
| 论坛回收站 » Please help experts to rewrite a batch processing. |
| Printable Version 2,038 / 5 |
| Floor1 kaixin1228 | Posted 2009-09-15 04:48 |
| 新手上路 Posts 6 Credits 10 | |
|
I want to write a batch file with the following requirements:
1. The value in file test.txt is 0 or 1; 2. If the read value is 0, call a.exe, if the read value is 1, call b.exe This is the batch file I wrote: FOR /F "delims=" %%a in (test.txt) do if "%%a"=="0" (call a.exe) else call b.exe When executed under DOS 6.22, it reports a syntax error. Please help rewrite it, thank you! [ Last edited by kaixin1228 on 2009-9-15 at 22:50 ] |
|
| Floor2 Hanyeguxing | Posted 2009-09-15 05:08 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
The return code read by batch processing can only be %ERRORLEVEL%
1. echo;%%a to see what is returned exactly 2. Upload your test.exe 3. If you don't need to write if so complicated, if %%a only has the possibility of 0 or 1, then it can be directly written as if %%a equ 0 (call a.exe) else call b.exe or if %%a equ 1 (call b.exe) else call a.exe |
|
| Floor3 kaixin1228 | Posted 2009-09-15 05:49 |
| 新手上路 Posts 6 Credits 10 | |
|
The source code of test.exe is as follows:
unsigned char main(void) { unsigned char value=0; value=inport(0x1e8); return value; } Just tried the return value: for /f %%a in(test.exe) do echo %%a Reports a syntax error [ Last edited by kaixin1228 on 2009-9-15 at 05:56 ] |
|
| Floor4 Hanyeguxing | Posted 2009-09-15 06:05 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
You can try it like this:
After the test is successful, change it to: [ Last edited by Hanyeguxing on 2009-9-15 at 06:07 ] |
|
| Floor5 kaixin1228 | Posted 2009-09-15 06:14 |
| 新手上路 Posts 6 Credits 10 | |
|
It reports Syntax error
|
|
| Floor6 904055262 | Posted 2009-09-15 06:40 |
| 新手上路 Posts 10 Credits 13 | |
|
CMD should not return the %errorleve% of an external program, unless that program returns an errorlevel to CMD. For example, the command line of 7Z, when decompressed correctly, returns 0 to CMD. Hehe, just talking nonsense, I don't know very well.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |