一个.NET EXE的一个bat文件捕获返回值返回值、文件、NET、EXE

2023-09-04 04:24:36 作者:是有多难忘才会刻苦铭心

我目前运行的是从一些其他的EXE一个bat文件调用一个EXE应用程序。什么IAM试图做的是我想从EXE返回一个值,并将其传递给其他的EXE的bat文件。我修改主要在我的控制台返回类型为整数,但无法访问在.bat文件的值,除非ERRORLEVEL其中我不想这样做,因为它可以消除任何潜在的错误。如果我使用ERRORLEVEL获取返回值如发生错误,它返回一个错误的整数,我怎么能区分哪些IAM返回整数值,这个数值之间。请让我知道你在此输入。

 关闭@echo
设置PATH =%PATH%; C:\脚本
bat文件:
TestConsoleApplication.exe
ECHO%ERRORLEVEL% - 要在这里拍摄返回EXE的价值不希望它使用ERRORLEVEL做
 

解决方案

如果你的EXE目前不使用标准输出,那么你可以简单地将结果写入到stdout的地方,可以通过父批处理过程中被捕获。

怎么将两个BAT文件压缩的一个EXE文件

例如,如果你的EXE(MYPROG.EXE)要输出

  VAR1 =我的第一个值
VAR2 = 23
 

那么这个简单的脚本可以被用来执行EXE和捕捉并存储结果

  FOR / Fdelims =%%一个在('MYPROG.EXE')并设置%%一个
 

即使正在使用标准输出,你也许可以将结果添加到输出中,你可以分析出你所需要的批次内的值这样的方式。但是有一个更简单的方法,如果stdout是不方便。

让你的EXE创建设置值的临时批处理文件。然后,您的批处理文件可以调用临时批处理文件,EXE完成后,然后删除该临时批处理文件。

I am currently running an EXE application which is called from a bat file with some other exes. What iam trying to do is i want to return a value from EXE and pass it to an other EXE in bat file. I modified Main in my console to return type as an integer but unable to access value in Bat file except in ERRORLEVEL which i dont want to do as it may erase any potential errors. If i use ERRORLEVEL to capture return value for instance an error occured and it returns a error integer, how can i distinguish between the integer value which iam returning and this value. Please let me know your input on this.

@echo off
set PATH=%PATH%;C:\Scripts
Bat File:
TestConsoleApplication.exe
ECHO %ERRORLEVEL% -- Want to capture here return value of EXE dont want to do it using ERRORLEVEL

解决方案

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.