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-25 05:53
中国DOS联盟论坛 » 论坛回收站 » Please help experts to rewrite a batch processing. View 1,720 Replies 5
Original Poster Posted 2009-09-15 04:48 ·  中国 北京 鹏博士BGP
新手上路
Credits 10
Posts 6
Joined 2007-08-16 16:51
18-year member
UID 95262
Gender Male
Status Offline
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 ]
Floor 2 Posted 2009-09-15 05:08 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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
Floor 3 Posted 2009-09-15 05:49 ·  中国 北京 鹏博士BGP
新手上路
Credits 10
Posts 6
Joined 2007-08-16 16:51
18-year member
UID 95262
Gender Male
Status Offline
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 ]
Floor 4 Posted 2009-09-15 06:05 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
You can try it like this:

test.exe>nul 2>nul
if %ERRORLEVEL% equ 0 (echo Return 0 or default to 0) else echo Success returns 1
pause

After the test is successful, change it to:

test.exe>nul 2>nul
if %ERRORLEVEL% equ 0 (call a.exe) else call b.exe


[ Last edited by Hanyeguxing on 2009-9-15 at 06:07 ]
Floor 5 Posted 2009-09-15 06:14 ·  中国 北京 鹏博士BGP
新手上路
Credits 10
Posts 6
Joined 2007-08-16 16:51
18-year member
UID 95262
Gender Male
Status Offline
It reports Syntax error
Floor 6 Posted 2009-09-15 06:40 ·  中国 江西 南昌 电信
新手上路
Credits 13
Posts 10
Joined 2009-09-07 02:10
16-year member
UID 151591
Gender Male
Status Offline
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.
Forum Jump: