Get the return value from executable jar launched from MFC(c++) Application

I am developing a project where I am launching a jar file. I want a return value from that jar file. I have surfed on net and got a clue that System.exit(n); can be read from the program from where am launching it. I also came to know that I can read it using shell script. But I am completely unaware of what how to write a shell script. I am new to MFC(C++). The code used to launch the jar file is as follows.

void CDropboxSync::OnBnClickedDbxPcToCloud()
    STARTUPINFOW        siStartupInfo;

    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    memset(&piProcessInfo, 0, sizeof(piProcessInfo)); 
    SetCursor(LoadCursor(NULL, IDC_WAIT));
    if (CreateProcess(m_csJrePath, TEXT(" -jar DbxUpldDwnld.jar u"), NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, (LPSTARTUPINFOA)&siStartupInfo, &piProcessInfo) == false) {
        AfxMessageBox(_T("Please install Java Runtime Environment(JRE) on your PC\n Or JRE not found on given path in INI File."), MB_ICONERROR);

    // TODO: Add your control notification handler code here

So from here how can I get the return value from the JAR file. All the experts out their please help me. Thanks in advance.


I don't think you should mix shell scripts and MFC. You launched the process from your program and you can call:

DWORD exitStatus;
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(piProcessInfo.hProcess, &exitStatus);

to obtain the exit code of a process you launched. Make sure to call this before you call CloseHandle(piProcessInfo.hProcess);

It it true though that maybe you'll find it more convenient to wrap the process you are launching in a shell script, but that doesn't make any difference to your MFC code.

Need Your Help

Using ACF fields in archive page for custom posts

php wordpress archive advanced-custom-fields

I've created a custom posts called Projects and created a Projects template inside of archive-projects.php. I've also created a single-projects.php to display individual project. However, this beca...

C header files and dynamic linking error

c header-files dynamic-library

I have created a dynamically linked library. The only problem I have is that my main program does not recognize my header file. The header file is in a separate folder from my main program. I have ...