批处理文件从exe获取返回值 [英] Batch-file get return Value from exe

查看:846
本文介绍了批处理文件从exe获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的C程序DOW.exe,返回值是星期几.我的批处理文件需要这个,所以我该怎么做,如何获得返回值?

I wrote a simple c-program DOW.exe, the return value is the day of week. I need this for my batchfile, so how can i do this, how can i get the return value ?

DOW.exe:Tu

DOW.exe: Tu

我的批处理文件(无效):

my batchfile (doesn't work):

set day = DOW.exe

echo = %day%

推荐答案

如果似乎dow.exe文件在一周中的某天作为文本回显到控制台(程序的标准输出),则:

If, as seems, the dow.exe file echoes to console (stdout from the program) the day of week as text, then:

从命令行

for /f %a in ('dow.exe') do set "dow=%a"

要在批处理文件中使用,必须转义百分号

For usage inside a batch file, percent signs need to be escaped

for /f %%a in ('dow.exe') do set "dow=%%a"

它的作用是执行指示的命令,检索其输出,并为其中的每一行执行do子句之后的代码,并将检索到的行存储在for可替换参数(本例中的%%a情况)

What it does is execute the indicated command, retrieve its output and for each line in it, execute the code after the do clause, with the line retrieved stored inside the for replaceable parameter (%%a in this case)

这篇关于批处理文件从exe获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆