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. How to send commands to a running application from the command line?

How to send commands to a running application from the command line?

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
10 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.
  • T Offline
    T Offline
    Ted On The Net
    wrote on last edited by
    #1

    Hi, I want to be able to send commands to a running application from the command line. Is there a simple way to do this? Thanks in advance for any help. Ted

    - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

    L OriginalGriffO P 3 Replies Last reply
    0
    • T Ted On The Net

      Hi, I want to be able to send commands to a running application from the command line. Is there a simple way to do this? Thanks in advance for any help. Ted

      - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

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

      Is the application already running on the commandline, or are you starting a console-application? If you're starting the proces yourself (using Process) then you could redirect the Standard Input[^] device.

      I are Troll :suss:

      T 1 Reply Last reply
      0
      • L Lost User

        Is the application already running on the commandline, or are you starting a console-application? If you're starting the proces yourself (using Process) then you could redirect the Standard Input[^] device.

        I are Troll :suss:

        T Offline
        T Offline
        Ted On The Net
        wrote on last edited by
        #3

        Perhaps it needed a little bit more explanation. In Delphi, I wrote a program for clients that listened to UDP. On the server I sometimes started a broadcaster (from the command line) to send a message to the clients (after sending the message the broacast app shuts down again). Now in C# I'm gonna rebuild this program. The client will be the same, but on the server the application will keep running because of added functionality. So, the app is a GUI app (dont know if it will be winforms or wpf yet) which will be running constantly. I just want to send some kind of command from the command line to the server and have the server app handle the messaging to the clients. Ofcourse, I could also split the server app in 2 programs (the original broadcaster) and another app to do the extra stuff. But the server app will also log the messages sent, so thats why i wanted to build one tool for the server which does all the work.. Better explained this way? or even more vague? :D Ted

        - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

        S L 2 Replies Last reply
        0
        • T Ted On The Net

          Hi, I want to be able to send commands to a running application from the command line. Is there a simple way to do this? Thanks in advance for any help. Ted

          - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          There is no simple way to do this. You would have to write a command line application that communicated to the running application, either via Remoting or via a common text file or database. I would recommend Remoting[^] as it will be more flexible and less processor / disk intensive.

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          T 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            There is no simple way to do this. You would have to write a command line application that communicated to the running application, either via Remoting or via a common text file or database. I would recommend Remoting[^] as it will be more flexible and less processor / disk intensive.

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            T Offline
            T Offline
            Ted On The Net
            wrote on last edited by
            #5

            the command sent from commandline is part of a batchfile running. perhaps I should split the tool like i said in the reply to Eddy on the other thread.

            - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

            1 Reply Last reply
            0
            • T Ted On The Net

              Perhaps it needed a little bit more explanation. In Delphi, I wrote a program for clients that listened to UDP. On the server I sometimes started a broadcaster (from the command line) to send a message to the clients (after sending the message the broacast app shuts down again). Now in C# I'm gonna rebuild this program. The client will be the same, but on the server the application will keep running because of added functionality. So, the app is a GUI app (dont know if it will be winforms or wpf yet) which will be running constantly. I just want to send some kind of command from the command line to the server and have the server app handle the messaging to the clients. Ofcourse, I could also split the server app in 2 programs (the original broadcaster) and another app to do the extra stuff. But the server app will also log the messages sent, so thats why i wanted to build one tool for the server which does all the work.. Better explained this way? or even more vague? :D Ted

              - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

              S Offline
              S Offline
              Som Shekhar
              wrote on last edited by
              #6

              What you say is really difficult to achieve. Probably you should consider the approach of DataBase Servers like MySql. There is a service running and you can still run commands on those servers from command line. But in this case, there is a new instance of program that sends the data through port to the running service. Hence, what you can do : 1. Instead of accepting the input from commandline, accept it through port. You already have a port handler in your server. 2. Create a CommandLine application to accept data from keyboard, send it through port to the service. Now the user can simply type the command in the commandline, it gets routed through the port and goes to the server. Added benefit is that this can be userful for remote monitoring as well.

              1 Reply Last reply
              0
              • T Ted On The Net

                Perhaps it needed a little bit more explanation. In Delphi, I wrote a program for clients that listened to UDP. On the server I sometimes started a broadcaster (from the command line) to send a message to the clients (after sending the message the broacast app shuts down again). Now in C# I'm gonna rebuild this program. The client will be the same, but on the server the application will keep running because of added functionality. So, the app is a GUI app (dont know if it will be winforms or wpf yet) which will be running constantly. I just want to send some kind of command from the command line to the server and have the server app handle the messaging to the clients. Ofcourse, I could also split the server app in 2 programs (the original broadcaster) and another app to do the extra stuff. But the server app will also log the messages sent, so thats why i wanted to build one tool for the server which does all the work.. Better explained this way? or even more vague? :D Ted

                - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

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

                Ted On The Net wrote:

                Better explained this way? or even more vague?

                Bit of both; I fail to see from where you want to send commands to the command-line application. You mentioned that the broadcaster (the server) is a console-app. Am I right in understanding that the broadcaster tells the client "what" to start, or is it the broadcaster itself that needs to be steered?

                I are Troll :suss:

                T 1 Reply Last reply
                0
                • L Lost User

                  Ted On The Net wrote:

                  Better explained this way? or even more vague?

                  Bit of both; I fail to see from where you want to send commands to the command-line application. You mentioned that the broadcaster (the server) is a console-app. Am I right in understanding that the broadcaster tells the client "what" to start, or is it the broadcaster itself that needs to be steered?

                  I are Troll :suss:

                  T Offline
                  T Offline
                  Ted On The Net
                  wrote on last edited by
                  #8

                  ok, I need to be more clear :D Our release build process (compile, build, create iso, etc) is run multiple times a day with the use of 4NT batch files on a server. During the process, notifications about the progress are sent to all developers informing them about new compiler errors, files being locked etc. This way the people who need to fix something know they have to and the build process can be fired up again ASAP. They receive these messages in a small receiver app using UDP. The messages are sent with a broadcaster app using command line parameters. In the batch files we just execute the broadcast tool with some parameters, it sends the message and shuts down again. (like: broadcast / broadcast error file not found: aFile.exe). The broadcaster and receiver tools are all built in Delphi. I want to rebuild it using C# as my first project (i'm currently making the transition from Delphi to C# guru (inhouse) :P) Do you get the idea now? :-) (hope so!)

                  - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

                  L 1 Reply Last reply
                  0
                  • T Ted On The Net

                    ok, I need to be more clear :D Our release build process (compile, build, create iso, etc) is run multiple times a day with the use of 4NT batch files on a server. During the process, notifications about the progress are sent to all developers informing them about new compiler errors, files being locked etc. This way the people who need to fix something know they have to and the build process can be fired up again ASAP. They receive these messages in a small receiver app using UDP. The messages are sent with a broadcaster app using command line parameters. In the batch files we just execute the broadcast tool with some parameters, it sends the message and shuts down again. (like: broadcast / broadcast error file not found: aFile.exe). The broadcaster and receiver tools are all built in Delphi. I want to rebuild it using C# as my first project (i'm currently making the transition from Delphi to C# guru (inhouse) :P) Do you get the idea now? :-) (hope so!)

                    - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

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

                    Ted On The Net wrote:

                    (like: broadcast / broadcast error file not found: aFile.exe). The broadcaster and receiver tools are all built in Delphi. I want to rebuild it using C# as my first project

                    Two applications to migrate, starting with the broadcaster. As soon as you create a new console-application you'll see where to get the command-line arguments from. Are all options specified as arguments, or will you be reading user-input directly from the console? Coming from Delphi, I guessed that it's now based on the Indy-components? You might be interested in the example on the UdpClient[^] class.

                    I are Troll :suss:

                    1 Reply Last reply
                    0
                    • T Ted On The Net

                      Hi, I want to be able to send commands to a running application from the command line. Is there a simple way to do this? Thanks in advance for any help. Ted

                      - Life would be so much easier if I had the source code! - If C# had true garbage collection, most applications would delete themselves upon execution ;)

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #10

                      The program would have to have that capability built in. One simple way would be having the application check a database for actions to take. Then you just deposit your instructions there. Another way is to use a Windows Service and send custom actions to it.

                      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