in reply to The return code from Perl is not returned to the application

It would be helpful to have:

It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^2: The return code from Perl is not returned to the application
by ueua (Initiate) on Dec 10, 2013 at 05:44 UTC

    I am sorry for the delay in my response.

    >an example of how you are exiting the Perl script (i.e. are you using exit?)
    Yes, I am using exit like folloing code.

    ---- perl script ----
    #unlock the file and output the log
    &exit_instance;
    
    #return exit code to C program.
    POSIX:_exit($ret ? EXIT_SUCCESS : EXIT_FAILURE);
    ---- perl script ----
    

    >an example of how you are spawning/forking the Perl script from your C program,
    >and how you wait for it to finish and process the return code.
    The daemon run C programs using CreateProcess() in Windows.
    And, C program run a Perl script using system().
    ---- Daemon ----
    if( TRUE != CreateProcess( NULL, commandLine, &sa, &sa, TRUE, CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS, NULL, NULL,
    			&StartInfo, &ProcInfo ) ) {
    	dRet = GetLastError();
    	LOGOUTPUT_ERR_WITHNUM_WIN( 0, MS_M_CREATEPROC_E, dRet );
    	return dRet;
    }
    ---- Daemon ----
    

    ---- C program ----
    #szCmd means perl command
    if (-1 == (ret = system(szCmd))) {
    	err = errno;
    	printf("Execution failure.%d\n", err);
    	return EXIT_FAILURE;
    }
    return ret;
    ---- C program ----
    
    As an image, look at the following flow.
    1. daemon -(launch)-> C program(1)
              -(launch)-> C program(2)
              -(launch)-> C program(3)
    
    2. C program(1) -(launch)-> perl script(1)
       C program(2) -(launch)-> perl script(2)
       C program(3) -(launch)-> perl script(3)
    
    3. perl script(1) -> get information from ESX server and write it to text
       perl script(2) -> wait for information about ESX server(i.e. wait until perl script(1) write a text)
       perl script(3) -> wait for information about ESX server(i.e. wait until perl script(1) write a text)
    
    4. after (3), each perl script process get information from text, and analyze it.
    
    As I already wrote, perl script outputs the logs at the start and the end of operation.
    From the logs ,we could see that the process had been finished successfully.
    But, after the logs had been written, the exit code that should be returned from Perl command to C command had not been returned.
    I really do not know, how to solve this problem.