none
如何在VC程序中接收bat的返回值? RRS feed

答案

  • 你好:

     STARTUPINFO startupInfor;
    	 PROCESS_INFORMATION processInfor; 
    	 memset(&startupInfor, 0, 
    		 sizeof(startupInfor));
    	 memset(&processInfor, 0, 
    		 sizeof(processInfor));
    	 startupInfor.cb = sizeof(startupInfor);
    	 if(::CreateProcess(NULL,"E:\\test.bat", 0, 0, FALSE, 
    		 CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS, 0, 0, 
    		 &startupInfor, &processInfor) == FALSE) return;
    	 ::WaitForSingleObject(processInfor.hProcess, INFINITE);
    	 DWORD exitCode;
    	 ::GetExitCodeProcess(processInfor.hProcess, &exitCode);

    假设你的批处理文件test.bat的返回值是4(exit 4)
    那么exitCode里得到的值是4。

     

    2014年2月28日 8:35
    版主