Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch-file get return Value from 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

my batchfile (doesn't work):

set day = DOW.exe

echo = %day%
like image 789
rapha31 Avatar asked Nov 04 '14 10:11

rapha31


2 Answers

Use %ERRORLEVEL%. Like echo %ERRORLEVEL.

like image 51
ttaaoossuuuu Avatar answered Sep 28 '22 16:09

ttaaoossuuuu


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

From command line

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"

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)

like image 34
MC ND Avatar answered Sep 28 '22 17:09

MC ND