Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取批处理文件中C程序的返回值_C_Batch File - Fatal编程技术网

获取批处理文件中C程序的返回值

获取批处理文件中C程序的返回值,c,batch-file,C,Batch File,我有一个编译为say demo.exe的c程序,它将使用批处理文件或python脚本运行。 C程序将返回我需要在批处理文件或python脚本中捕获的错误代码 下面是windows上C的一个示例程序 #include <stdio.h> #include <stdlib.h> int func() { return(44); } void fun(void) { func(); } int main(int argc, char *argv[

我有一个编译为say demo.exe的c程序,它将使用批处理文件或python脚本运行。 C程序将返回我需要在批处理文件或python脚本中捕获的错误代码

下面是windows上C的一个示例程序

#include <stdio.h>
#include <stdlib.h>

int func()
{
    return(44);
}

void fun(void)
{
        func();
}


int main(int argc, char *argv[])
{
    int c = atexit(fun);
        printf("c = %dn", c);

    return(74);
}
结果如下:

C:\Users\USER4\Downloads>demo.bat
==================================== FIRST BATCH TEST SCRIPT ====================================
c = 0ndemo.exe
demo.exe returns "demo.exe"
FAILED
==================================== SECOND BATCH TEST SCRIPT ====================================
demo.exe
==================================== THIRD BATCH TEST SCRIPT ====================================
c = 0nNo Error. Error code = demo.exe
Press any key to continue . . .
ERRORLEVEL总是作为exe的名称出现。
如何在批处理文件中获取C程序的返回值?

为什么将其标记为
python
ERRORLEVEL
不是
%ERRORLEVEL%
。如果您想要退出代码,请参见主菜单中的“您应该退出”
not
return
,如
exit(74)
,这是否回答了您的问题@查特隆
返回74
。有,但这不是其中之一。
C:\Users\USER4\Downloads>demo.bat
==================================== FIRST BATCH TEST SCRIPT ====================================
c = 0ndemo.exe
demo.exe returns "demo.exe"
FAILED
==================================== SECOND BATCH TEST SCRIPT ====================================
demo.exe
==================================== THIRD BATCH TEST SCRIPT ====================================
c = 0nNo Error. Error code = demo.exe
Press any key to continue . . .