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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How do I 'drive' a command line utility beyond executing a single process / command?

How do I 'drive' a command line utility beyond executing a single process / command?

Scheduled Pinned Locked Moved C#
helpquestioncomtoolstutorial
11 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.
  • M Mouldiwarp

    Hi, this is my first post so hopefully I get everything in here that I need too. Here is my problem, I have a command line utility that once running accepts commands / input before displaying results. To keep things simple I am starting to build my understanding using nslookup. ALl the threads I have found so far relate to executing a command and capturing output, nothing about actually 'driving' a command line utility through the secondary input of commands / instructions. Can someone help me out here... as mentioned, using nslookup as a sample utility I want to be able to: - Launch the nslookup utility with no arguments or parameters (this I can do). - At the point NSLookup returns the '>' prompt, I want to send some input / issue a command to the utility. For example www.codeproject.com. - I want to capture the results / output of the execution so that I can analyse the text stream within my application, and retain enough control to submit a second instruction to nslookup (i.e. it doesnt exit until I choose to exit). Any help greatly appreciated

    C Offline
    C Offline
    Calla
    wrote on last edited by
    #2

    I guess you have to start nslookup with arguments and then parse the output yourself. Just running nsloolup.exe without parameters will only start the application itself (as you have discovered).

    1 Reply Last reply
    0
    • M Mouldiwarp

      Hi, this is my first post so hopefully I get everything in here that I need too. Here is my problem, I have a command line utility that once running accepts commands / input before displaying results. To keep things simple I am starting to build my understanding using nslookup. ALl the threads I have found so far relate to executing a command and capturing output, nothing about actually 'driving' a command line utility through the secondary input of commands / instructions. Can someone help me out here... as mentioned, using nslookup as a sample utility I want to be able to: - Launch the nslookup utility with no arguments or parameters (this I can do). - At the point NSLookup returns the '>' prompt, I want to send some input / issue a command to the utility. For example www.codeproject.com. - I want to capture the results / output of the execution so that I can analyse the text stream within my application, and retain enough control to submit a second instruction to nslookup (i.e. it doesnt exit until I choose to exit). Any help greatly appreciated

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #3

      You can get the output generated by the commandline app (I forget exactly how this is done), and then respond to that.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      1 Reply Last reply
      0
      • M Mouldiwarp

        Hi, this is my first post so hopefully I get everything in here that I need too. Here is my problem, I have a command line utility that once running accepts commands / input before displaying results. To keep things simple I am starting to build my understanding using nslookup. ALl the threads I have found so far relate to executing a command and capturing output, nothing about actually 'driving' a command line utility through the secondary input of commands / instructions. Can someone help me out here... as mentioned, using nslookup as a sample utility I want to be able to: - Launch the nslookup utility with no arguments or parameters (this I can do). - At the point NSLookup returns the '>' prompt, I want to send some input / issue a command to the utility. For example www.codeproject.com. - I want to capture the results / output of the execution so that I can analyse the text stream within my application, and retain enough control to submit a second instruction to nslookup (i.e. it doesnt exit until I choose to exit). Any help greatly appreciated

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #4

        What you want is input/output/error redirection of a process, which is supported by the Process class. Have a look at the following stream-related Process members: properties StandardInput, StandardOutput, StandardError events OutputDataReceived, ErrorDataReceived As an alternative to using events, you could create a few threads, each dealing with one of the streams, based on a loop calling Read() or ReadLine(). Do not use ReadToEnd() on the output/error streams as they would probably block until the process exits. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


        P 2 Replies Last reply
        0
        • M Mouldiwarp

          Hi, this is my first post so hopefully I get everything in here that I need too. Here is my problem, I have a command line utility that once running accepts commands / input before displaying results. To keep things simple I am starting to build my understanding using nslookup. ALl the threads I have found so far relate to executing a command and capturing output, nothing about actually 'driving' a command line utility through the secondary input of commands / instructions. Can someone help me out here... as mentioned, using nslookup as a sample utility I want to be able to: - Launch the nslookup utility with no arguments or parameters (this I can do). - At the point NSLookup returns the '>' prompt, I want to send some input / issue a command to the utility. For example www.codeproject.com. - I want to capture the results / output of the execution so that I can analyse the text stream within my application, and retain enough control to submit a second instruction to nslookup (i.e. it doesnt exit until I choose to exit). Any help greatly appreciated

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

          I haven't done that on a local system; only on a remote system -- by telnetting in and using a script to interact with the remote system. It occurred to me today (before I even read your post) that my script engine might be able to work locally. My article on my script engine is nearing completion; I hope to finish it up today.

          M 1 Reply Last reply
          0
          • L Luc Pattyn

            What you want is input/output/error redirection of a process, which is supported by the Process class. Have a look at the following stream-related Process members: properties StandardInput, StandardOutput, StandardError events OutputDataReceived, ErrorDataReceived As an alternative to using events, you could create a few threads, each dealing with one of the streams, based on a loop calling Read() or ReadLine(). Do not use ReadToEnd() on the output/error streams as they would probably block until the process exits. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


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

            Veddy intewesting... ... and then I wrap it in an IScriptableCommunicator[^]... :cool:

            1 Reply Last reply
            0
            • P PIEBALDconsult

              I haven't done that on a local system; only on a remote system -- by telnetting in and using a script to interact with the remote system. It occurred to me today (before I even read your post) that my script engine might be able to work locally. My article on my script engine is nearing completion; I hope to finish it up today.

              M Offline
              M Offline
              Mouldiwarp
              wrote on last edited by
              #7

              That sounds like it could be interesting :) Look forward to reading it.!!

              P 1 Reply Last reply
              0
              • M Mouldiwarp

                That sounds like it could be interesting :) Look forward to reading it.!!

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

                I have a working example going now. It works with nslookup and at least one utility of my own, but not FTP and TELNET -- they don't prompt when executed in this manner. :mad: How have you progressed in the meantime? P.S. And I did post my script article. I'm just working on the class that wraps a Process so the engine can use it.

                M 1 Reply Last reply
                0
                • L Luc Pattyn

                  What you want is input/output/error redirection of a process, which is supported by the Process class. Have a look at the following stream-related Process members: properties StandardInput, StandardOutput, StandardError events OutputDataReceived, ErrorDataReceived As an alternative to using events, you could create a few threads, each dealing with one of the streams, based on a loop calling Read() or ReadLine(). Do not use ReadToEnd() on the output/error streams as they would probably block until the process exits. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


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

                  This is what I'm playing around with. Except for reading the error stream, and utilities that don't prompt when executed this way, it works pretty well.

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    I have a working example going now. It works with nslookup and at least one utility of my own, but not FTP and TELNET -- they don't prompt when executed in this manner. :mad: How have you progressed in the meantime? P.S. And I did post my script article. I'm just working on the class that wraps a Process so the engine can use it.

                    M Offline
                    M Offline
                    Mouldiwarp
                    wrote on last edited by
                    #10

                    As a newbie to code writing this one got me really stumped. While I have been contemplating and get help from people here I turned my attention to some other area's that I need to master in order to get to the end of my project. I am now able to churn out windoes services / service installers etc... without much hassle.... all I need to do now is to get my service to drive these cmd line utilities :D I havent looked yet but am looking forward to seeing what you have done and how you did it.

                    1 Reply Last reply
                    0
                    • M Mouldiwarp

                      Hi, this is my first post so hopefully I get everything in here that I need too. Here is my problem, I have a command line utility that once running accepts commands / input before displaying results. To keep things simple I am starting to build my understanding using nslookup. ALl the threads I have found so far relate to executing a command and capturing output, nothing about actually 'driving' a command line utility through the secondary input of commands / instructions. Can someone help me out here... as mentioned, using nslookup as a sample utility I want to be able to: - Launch the nslookup utility with no arguments or parameters (this I can do). - At the point NSLookup returns the '>' prompt, I want to send some input / issue a command to the utility. For example www.codeproject.com. - I want to capture the results / output of the execution so that I can analyse the text stream within my application, and retain enough control to submit a second instruction to nslookup (i.e. it doesnt exit until I choose to exit). Any help greatly appreciated

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

                      Just got published: ProcessCommunicator[^] Let me know what you think.

                      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