Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# application obtain results of program it executes

C# application obtain results of program it executes

Scheduled Pinned Locked Moved C#
questioncsharptutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcof
    wrote on last edited by
    #1

    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 spcific 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?

    L D M 3 Replies Last reply
    0
    • D dcof

      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 spcific 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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I believe you must be using the Process class to run you console application, in which case you can use the Process.StandardOutput[^] to get a StreamReader object to read the output from you console app.

      1 Reply Last reply
      0
      • D dcof

        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 spcific 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?

        D Offline
        D Offline
        dbaseman
        wrote on last edited by
        #3

        I think it would be better to reorganize your code. The console project you wrote really should be a library/API, if you're going to consume it from another application (ie, the windows service). I'd suggest converting your console application into a class library project. Then, both the windows service and console can create their own implementations. So, let's say you execute the console app like this: myconsoleapp.exe "servicename" Then, create a library project with a public method "RunService":

        public class MyAPI
        {
            public string ExecuteService(string serviceName)
            {
                // logic goes here
            }
        }
        

        Now both the console app, and your new windows service can consume MyAPI as needed.

        J 1 Reply Last reply
        0
        • D dbaseman

          I think it would be better to reorganize your code. The console project you wrote really should be a library/API, if you're going to consume it from another application (ie, the windows service). I'd suggest converting your console application into a class library project. Then, both the windows service and console can create their own implementations. So, let's say you execute the console app like this: myconsoleapp.exe "servicename" Then, create a library project with a public method "RunService":

          public class MyAPI
          {
              public string ExecuteService(string serviceName)
              {
                  // logic goes here
              }
          }
          

          Now both the console app, and your new windows service can consume MyAPI as needed.

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          dbaseman wrote:

          Now both the console app, and your new windows service can consume MyAPI as needed

          Of course it would require quite a bit more work than that. After all it probably takes input, and that would need to be dealt with. And it definitely creates output, which the OP mentioned, and that too would need to be dealt with.

          D 1 Reply Last reply
          0
          • D dcof

            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 spcific 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?

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            I never really liked console apps, here is what I would do. Create a windows forms app that will allow you to input information, a button and a display control. The input will be specific to our needs and set the defaults to the test information. The button will call the method you use in the console app The output (I usually use a listbox ot a textbox) will take the output you are currently using. I find this the easiest way to debug an console app that has been snaffled from the interweb. Make sure you keep all your processing (the console methods) in a seperate class as it is then easy to create a library class from that (as jschell suggested).

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • J jschell

              dbaseman wrote:

              Now both the console app, and your new windows service can consume MyAPI as needed

              Of course it would require quite a bit more work than that. After all it probably takes input, and that would need to be dealt with. And it definitely creates output, which the OP mentioned, and that too would need to be dealt with.

              D Offline
              D Offline
              dbaseman
              wrote on last edited by
              #6

              Right, of course, but my point is that it's far better to interact with an API, than trying to parse the output from a console application.

              J 1 Reply Last reply
              0
              • D dbaseman

                Right, of course, but my point is that it's far better to interact with an API, than trying to parse the output from a console application.

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                dbaseman wrote:

                but my point is that it's far better

                No not really. Sometime it can be much better not to do it that way. For example, if one has a server and one needs to interact with unmanaged C++ code in C# where the C++ code is known to be flaky (or even might be.) Because one doesn't want the server to exit every time the C++ code throws a system exception. Or because one doesn't have the original code. Or doesn't have a license to modify it. Or because one has a number of applications, all supporting the same idiom (console) and a single solution versus numerous others is more cost effective.

                D 1 Reply Last reply
                0
                • J jschell

                  dbaseman wrote:

                  but my point is that it's far better

                  No not really. Sometime it can be much better not to do it that way. For example, if one has a server and one needs to interact with unmanaged C++ code in C# where the C++ code is known to be flaky (or even might be.) Because one doesn't want the server to exit every time the C++ code throws a system exception. Or because one doesn't have the original code. Or doesn't have a license to modify it. Or because one has a number of applications, all supporting the same idiom (console) and a single solution versus numerous others is more cost effective.

                  D Offline
                  D Offline
                  dbaseman
                  wrote on last edited by
                  #8

                  That's an interesting point, but I'm not sure how it's relevant to the question (remember, this relates to a C# console app).

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups