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-08-01 12:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to send the execution result of an .EXE to a batch file? View 2,530 Replies 13
Original Poster Posted 2004-11-22 00:00 ·  中国 上海 嘉定区 电信
初级用户
Credits 160
Posts 15
Joined 2004-07-12 00:00
22-year member
UID 28236
Gender Male
Status Offline
I want to send the result of executing .EXE as a string into a batch file and use it as a variable in the batch. How to achieve this? Thanks!
Floor 2 Posted 2004-11-22 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
If you can describe the problem more clearly, I think your problem will be much easier to solve.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2004-11-22 00:00 ·  中国 上海 嘉定区 电信
初级用户
Credits 160
Posts 15
Joined 2004-07-12 00:00
22-year member
UID 28236
Gender Male
Status Offline
I now want to make the result of EXE running not return in the form of 0 or 1, but return a string, assign this string to a variable in the batch file, and compare it with the existing string in the batch file to see if the output characters are correct. How to implement it?
Floor 4 Posted 2004-11-22 00:00 ·  IANA 局域网IP(Private-Use)
初级用户
Credits 113
Posts 4
Joined 2004-11-22 00:00
21-year member
UID 33908
Gender Male
Status Offline
Yeah! I also want to know! Please teach! !
Floor 5 Posted 2004-11-22 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The result returned by an EXE file is not determined by your subjective wishes, but by the EXE file itself. You can use the errorlevel environment variable to judge the result returned by the EXE file. Of course, your batch processing can judge what situation the EXE file encountered during execution according to the value of errorlevel and display it.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2004-11-22 00:00 ·  IANA 局域网IP(Private-Use)
初级用户
Credits 113
Posts 4
Joined 2004-11-22 00:00
21-year member
UID 33908
Gender Male
Status Offline
By the way! Can we change to another solution! That is, write the required string into a file in the exe, and then the batch script reads the content of that file and assigns it to a variable for comparison?
Floor 7 Posted 2004-11-26 00:00 ·  中国 广东 深圳 中移铁通
初级用户
Credits 104
Posts 1
Joined 2004-10-28 00:00
21-year member
UID 33019
Gender Male
Status Offline
It can be achieved with setinfo.exe
Floor 8 Posted 2004-11-29 00:00 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
Floor 9 Posted 2004-12-04 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re windrate: This is certainly possible, provided that you can modify this program, whether it's modifying the source code or disassembling it. Additionally, outputting the program results to the system environment variables seems to be an old topic, and many solutions have emerged, but generally, it's to first generate a string similar to "set var=string" and then execute it as a command. Under moderate restrictive conditions (command extensions and third-party programs not allowed), you can use debug to generate a string prefix file, then append the program output to this file, and finally run it as a batch program. Under the highest restrictive conditions (command extensions and external commands not allowed), you can use a pre-edited string prefix file. Of course, you can also use the specific output of other specific commands (which may be internal or external commands), which is more complicated.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 10 Posted 2005-01-21 00:00 ·  中国 广东 潮州 电信
中级用户
★★
Credits 240
Posts 53
Joined 2005-01-21 00:00
21-year member
UID 35493
Gender Male
Status Offline
Is this EXE you wrote yourself? If so, you can take a look at this, which explains this method: http://www.doshome.com/bbs/dispbbs.asp?boardID=5&ID=7288
Floor 11 Posted 2005-01-21 00:00 ·  中国 甘肃 兰州 城关区 电信
初级用户
Credits 114
Posts 7
Joined 2005-01-21 00:00
21-year member
UID 35502
Gender Male
Status Offline
What the 3rd said is right. The redirection function means: your EXE program > result file name.
Floor 12 Posted 2005-02-21 00:00 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 369
Posts 87
Joined 2003-09-14 00:00
22-year member
UID 9822
Gender Male
Status Offline
If there is a return code (errorlevel), it's easy. Please see:
if errorlevel 1 set el=you are right
if errorlevel 2 set el=you are wrong
if %el%==you are right goto XXX
if %el%==you are wrong goto YYY
Floor 13 Posted 2005-02-21 00:00 ·  中国 河北 唐山 联通
版主
★★★
操作系统爱好者
Credits 1,113
Posts 392
Joined 2002-11-11 00:00
23-year member
UID 228
Gender Male
Status Offline
The key commands used are: > redirect to file, strings or inifile read strings. For the specific method, please refer to the help yourself.
DOS之家 http://doshome.com 站长 葛明阳
Floor 14 Posted 2005-02-22 00:00 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
The following is the speech of sunlight on 2004-11-22 9:36:43:
I want to send the result of.EXE execution as a string to the batch file and use it as a variable in the batch file. How to achieve it? Thanks!

If you must follow your idea, 4DOS can help you achieve it. It has a screen reading function, and then you can directly assign the read content to a variable. Of course, if you want to use this as a judgment condition for execution, you must know all possible execution results of the.EXE
Forum Jump: