Retrieving the result of a third party application

This is a discussion on Retrieving the result of a third party application within the Windows Programming forums, part of the Platform Specific Boards category; Okay, I haven't been programming in C++ for a while, only C#. In C# htis was easy, but in C++ ...

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139

    Retrieving the result of a third party application

    Okay, I haven't been programming in C++ for a while, only C#. In C# htis was easy, but in C++ I have some problems...

    I have a command line tool ( the Oracle SQLLdr in this case ) that I'd like to start and wait for. Works like a charm. However, I need to know if the started program terminated sucessfully. The Oracle documentation says the program will return 0 on success, other values for errors. Fine I thought, that's easy.

    Code:
    /// 
    /// Calls the SQLLDR process to load the file
    ///
    bool OracleTableLoadFile()
    {
    	if( ! CreateControlFile() )  return false;
    	
    	CString strParameters;
    	
    	strParameters.Format( _T("userid=%s/%s@%s control=%s.CTL data=%s bad=%s.BAD LOG=%s.LOG"),
    						m_strUser, 
    						m_strPassword,
    						m_strDatasource,
    						m_strOutput, 
    						m_strOutput,
    						m_strOutput,
    						m_strOutput );
    
    	SHELLEXECUTEINFO ExecuteInfo;
    
    	memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
    
    	ExecuteInfo.cbSize       = sizeof(ExecuteInfo);
    	ExecuteInfo.fMask        = SEE_MASK_NOCLOSEPROCESS;                
    	ExecuteInfo.hwnd         = 0;                
    	ExecuteInfo.lpVerb       = _T("open");
    	ExecuteInfo.lpFile       = _T("SQLLDR");
    	ExecuteInfo.lpParameters = strParameters;
    	ExecuteInfo.lpDirectory  = 0;
    	ExecuteInfo.nShow        = SW_SHOW;
    	ExecuteInfo.hInstApp     = 0;
    
    	if( ! ShellExecuteEx( &ExecuteInfo ) )
    	{
    		Error( _T( "Unable to start sql loader" ) );
    		return false;
    	}
    
    	WaitForSingleObject( ExecuteInfo.hProcess, INFINITE );
    
    
    
    	return true;
    }
    However, I found no way to retrieve my started applications return value. Not with the structure I have, nor with the structures of CreateProcess or even the dreaded WinExec. WaitForSingleObject and all process starting functions only return their own success or failure.

    How do I get the return value of my started app once it terminated ?

    Help me Obi-Wan CBoard, you are my only help...

    ( I'm pretty sure the answer will be simple, so here's my next post in advance: "DOH ! Thank you, I will take a course in googling and reading comprehension as soon as possible " )

    Edit:
    I can use _tsystem( ... ) for this, but it's not really what I want to do...
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    [edit]
    Down the bottom of the CreateProcess() documentation there is a link "Process and Thread Functions". Follow it and see what you find. Similar links are available for many winapi functions.
    [/edit]

    GetExitCodeProcess().

    Call it after the process has completed(as indicated by WaitForSingleObject). CreateProcess() is generally preferred for starting a program over ShellExecute(Ex).

    Remember to close ExecuteInfo.hProcess with CloseHandle() when you are done.
    --
    Code:
    	SHELLEXECUTEINFO ExecuteInfo;
    
    	memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
    As a side note, there is a cleaner way to do this:
    Code:
    	SHELLEXECUTEINFO ExecuteInfo = { 0 };
    Last edited by anonytmouse; 06-09-2004 at 04:31 AM.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Thanks a lot, that's what I was looking for !

    Geez, I wish I could go back to C#
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 12:29 PM
  2. Using internet browsers internally in application
    By alphaoide in forum Tech Board
    Replies: 5
    Last Post: 11-06-2005, 03:19 PM
  3. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 06:50 AM
  4. Windows form application and Windows application
    By |Wiz| in forum Windows Programming
    Replies: 5
    Last Post: 10-01-2005, 05:14 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21