批处理文件从exe获取返回值 [英] Batch-file get return Value from 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屋!