C# obtain information from program it executes

Answered C# obtain information from program it executes

  • Saturday, September 01, 2012 5:31 PM
     
     

    I have a question about how to obtain the results (condition codes and messages) from a C# 2008 console application.
      Basically I have received the C# 2008 console application code that calls a remote webservice and consumes the results. The console application runs by giving it commands to know what method in the web service to call.
      Now I am going to write a C# 2010 service application that will call the C# 2008 console and run the commands in a specificed order. There are three types of calls that need to be called in a specified order.

     This new application will call the console application by executing the commands in a specific order. However, I would like to know how this new application can obtain the results of the console application.
    How will the console application pass it's results back to my new application?

    Would it be better if I put the code I am describing in the application I am referring to? If so, can you tell me why and how to accomplsih that task?

All Replies

  • Saturday, September 01, 2012 5:42 PM
     
     
    Process.ExitCode will get the exit status value of the process you started, assuming you launched it from the new app using something like:
     
        Process p = Process.Start("SomeApp.exe");
        p.WaitForExit();
        int value = p.ExitCode;

    --
    Mike
  • Saturday, September 01, 2012 5:46 PM
     
     

    Would the code you just showed me, give me  the following:

    1. Condition code returend,

    2. The error messages (good and bad) messages that are used?

    3. log file messages from the program it ran?

    if not, can  you tell me how to obtain all these results?

  • Saturday, September 01, 2012 5:50 PM
     
     Answered
    It gives you what is documented here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx, which I believe to only be item 1.
     
    An application may or may not use a log file, as well as error messages.  There is no generic way to capture that type of info.
     
    How do you know this is a C# app that you are calling?  If you built it, put into it hooks to the info you need.  If you did not build it, then you are likley stuck with what you have.

    --
    Mike
    • Marked As Answer by wendy elizabeth Sunday, September 02, 2012 4:53 AM
    •  
  • Sunday, September 02, 2012 4:05 AM
     
     

    Thanks!