Capture return value of an .net EXE in an bat file

六眼飞鱼酱① 提交于 2019-12-06 16:38:17

Errorlevel will have the return value of the program you ran. You can't specify to not have it hold the return value of the program.

If you are worrying about other errors elsewhere in your script, you can check the errorlevel at those places and store the value in another variable or jump to a particular label that handles that error.

If your EXE does not currently use stdout then you can simply write the results to stdout where it can be captured by the parent batch process.

For example, if your EXE (myprog.exe) were to output

var1=my first value
var2=23

then this simple script could be used to execute the EXE and capture and store the results

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

Even if stdout is being used, you might be able to add the results to the output in such a way that you can parse out the values you need within the batch. But there is a simpler method if stdout is not convenient.

Have your EXE create a temporary batch file that sets the values. Your batch file can then call the temporary batch file after EXE completes and then delete the temp batch file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!