How to execute commands in Command Line?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Madhanmohan S

    How to execute commands in Command Line?

    Hi All,
    I want to run a command line appplication from C#. When i start
    the application, it will go into specific mode. After that, i have to give
    commands to use the application.
    How Can This Be Done in C#....

    Thanks and Regards,
    S.Madhanmohan


  • Jon Skeet

    #2
    Re: How to execute commands in Command Line?

    Madhanmohan S <ermadhan@hotma il.com> wrote:[color=blue]
    > I want to run a command line appplication from C#. When i start
    > the application, it will go into specific mode. After that, i have to give
    > commands to use the application.
    > How Can This Be Done in C#....[/color]

    Look at the System.Diagnost ics.Process class and its Start method. To
    write to the application's input, look at Process.Standar dInput. If you
    have any further questions, give a bit more detail.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Madhanmohan S

      #3
      Re: How to execute commands in Command Line?

      Hi,
      I have application which will run in commandline mode. When i start
      the application, it will go to a specific mode (Similar like, when we use
      OSql for MSDE). In this mode, we have to give different commands to execute
      our tasks. I tried with StandardInput Method. But i was not able to execute
      the commands, in the application mode.
      When i use the StandardInputMe thod to pass the commands, the C#
      application hangs.
      Can you point some resources or sample code for the same???


      "Jon Skeet" <skeet@pobox.co m> wrote in message
      news:MPG.19d394 911db174aa9896d f@news.microsof t.com...[color=blue]
      > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
      > > I want to run a command line appplication from C#. When i[/color][/color]
      start[color=blue][color=green]
      > > the application, it will go into specific mode. After that, i have to[/color][/color]
      give[color=blue][color=green]
      > > commands to use the application.
      > > How Can This Be Done in C#....[/color]
      >
      > Look at the System.Diagnost ics.Process class and its Start method. To
      > write to the application's input, look at Process.Standar dInput. If you
      > have any further questions, give a bit more detail.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet

        #4
        Re: How to execute commands in Command Line?

        Madhanmohan S <ermadhan@hotma il.com> wrote:[color=blue]
        > I have application which will run in commandline mode. When i start
        > the application, it will go to a specific mode (Similar like, when we use
        > OSql for MSDE). In this mode, we have to give different commands to execute
        > our tasks. I tried with StandardInput Method. But i was not able to execute
        > the commands, in the application mode.
        > When i use the StandardInputMe thod to pass the commands, the C#
        > application hangs.[/color]

        Are you reading from StandardOutput and StandardError? Perhaps the
        other process is blocking.
        [color=blue]
        > Can you point some resources or sample code for the same???[/color]

        Sure. First, a very simple echo program:

        using System;

        public class Echo
        {
        static void Main()
        {
        string line;
        while ((line=Console. ReadLine())!="q uit")
        Console.WriteLi ne ("Echo: {0}", line);
        }
        }

        Compile it (to echo.exe, as a command-line app) and run it - basically
        it echoes what you type until you type "quit".

        Now here's something to automate it:

        using System;
        using System.Diagnost ics;
        using System.IO;
        using System.Threadin g;

        public class AutoEcho
        {
        static void Main()
        {
        ProcessStartInf o psi = new ProcessStartInf o("echo.exe") ;
        psi.RedirectSta ndardOutput=tru e;
        psi.RedirectSta ndardInput=true ;
        psi.UseShellExe cute=false;
        psi.CreateNoWin dow=true;
        Process proc = Process.Start (psi);

        // Start a new thread to read from its standard output
        ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
        por.Start();

        proc.StandardIn put.WriteLine ("Hello");
        proc.StandardIn put.WriteLine ("There");
        proc.StandardIn put.WriteLine ("quit");
        }

        class ProcessOutputRe ader
        {
        Process proc;

        public ProcessOutputRe ader (Process proc)
        {
        this.proc = proc;
        }

        public void Start()
        {
        new Thread (new ThreadStart(Rea dAll)).Start();
        }

        void ReadAll()
        {
        StreamReader reader = proc.StandardOu tput;

        string line;

        while ((line = reader.ReadLine ())!=null)
        Console.WriteLi ne ("Process output: {0}", line);
        }
        }
        }


        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Madhanmohan S

          #5
          Re: How to execute commands in Command Line?

          Thank You For Your Help.......


          "Jon Skeet" <skeet@pobox.co m> wrote in message
          news:MPG.19d3a6 792a7269899896e 1@news.microsof t.com...[color=blue]
          > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
          > > I have application which will run in commandline mode. When i[/color][/color]
          start[color=blue][color=green]
          > > the application, it will go to a specific mode (Similar like, when we[/color][/color]
          use[color=blue][color=green]
          > > OSql for MSDE). In this mode, we have to give different commands to[/color][/color]
          execute[color=blue][color=green]
          > > our tasks. I tried with StandardInput Method. But i was not able to[/color][/color]
          execute[color=blue][color=green]
          > > the commands, in the application mode.
          > > When i use the StandardInputMe thod to pass the commands, the C#
          > > application hangs.[/color]
          >
          > Are you reading from StandardOutput and StandardError? Perhaps the
          > other process is blocking.
          >[color=green]
          > > Can you point some resources or sample code for the same???[/color]
          >
          > Sure. First, a very simple echo program:
          >
          > using System;
          >
          > public class Echo
          > {
          > static void Main()
          > {
          > string line;
          > while ((line=Console. ReadLine())!="q uit")
          > Console.WriteLi ne ("Echo: {0}", line);
          > }
          > }
          >
          > Compile it (to echo.exe, as a command-line app) and run it - basically
          > it echoes what you type until you type "quit".
          >
          > Now here's something to automate it:
          >
          > using System;
          > using System.Diagnost ics;
          > using System.IO;
          > using System.Threadin g;
          >
          > public class AutoEcho
          > {
          > static void Main()
          > {
          > ProcessStartInf o psi = new ProcessStartInf o("echo.exe") ;
          > psi.RedirectSta ndardOutput=tru e;
          > psi.RedirectSta ndardInput=true ;
          > psi.UseShellExe cute=false;
          > psi.CreateNoWin dow=true;
          > Process proc = Process.Start (psi);
          >
          > // Start a new thread to read from its standard output
          > ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
          > por.Start();
          >
          > proc.StandardIn put.WriteLine ("Hello");
          > proc.StandardIn put.WriteLine ("There");
          > proc.StandardIn put.WriteLine ("quit");
          > }
          >
          > class ProcessOutputRe ader
          > {
          > Process proc;
          >
          > public ProcessOutputRe ader (Process proc)
          > {
          > this.proc = proc;
          > }
          >
          > public void Start()
          > {
          > new Thread (new ThreadStart(Rea dAll)).Start();
          > }
          >
          > void ReadAll()
          > {
          > StreamReader reader = proc.StandardOu tput;
          >
          > string line;
          >
          > while ((line = reader.ReadLine ())!=null)
          > Console.WriteLi ne ("Process output: {0}", line);
          > }
          > }
          > }
          >
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Magnus Krisell

            #6
            Re: How to execute commands in Command Line?

            This is interesting.
            But how do I know if an existing executable writes its output to
            StandardOutput or StandardError?
            I tried to read the output from the Lame MP3 encoder, and it didn't
            work at first because it uses StandardError instead of StandardOutput.

            - Magnus

            "Jon Skeet" <skeet@pobox.co m> wrote in message
            news:MPG.19d3a6 792a7269899896e 1@news.microsof t.com...[color=blue]
            > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
            > > I have application which will run in commandline mode. When i[/color][/color]
            start[color=blue][color=green]
            > > the application, it will go to a specific mode (Similar like, when we[/color][/color]
            use[color=blue][color=green]
            > > OSql for MSDE). In this mode, we have to give different commands to[/color][/color]
            execute[color=blue][color=green]
            > > our tasks. I tried with StandardInput Method. But i was not able to[/color][/color]
            execute[color=blue][color=green]
            > > the commands, in the application mode.
            > > When i use the StandardInputMe thod to pass the commands, the C#
            > > application hangs.[/color]
            >
            > Are you reading from StandardOutput and StandardError? Perhaps the
            > other process is blocking.
            >[color=green]
            > > Can you point some resources or sample code for the same???[/color]
            >
            > Sure. First, a very simple echo program:
            >
            > using System;
            >
            > public class Echo
            > {
            > static void Main()
            > {
            > string line;
            > while ((line=Console. ReadLine())!="q uit")
            > Console.WriteLi ne ("Echo: {0}", line);
            > }
            > }
            >
            > Compile it (to echo.exe, as a command-line app) and run it - basically
            > it echoes what you type until you type "quit".
            >
            > Now here's something to automate it:
            >
            > using System;
            > using System.Diagnost ics;
            > using System.IO;
            > using System.Threadin g;
            >
            > public class AutoEcho
            > {
            > static void Main()
            > {
            > ProcessStartInf o psi = new ProcessStartInf o("echo.exe") ;
            > psi.RedirectSta ndardOutput=tru e;
            > psi.RedirectSta ndardInput=true ;
            > psi.UseShellExe cute=false;
            > psi.CreateNoWin dow=true;
            > Process proc = Process.Start (psi);
            >
            > // Start a new thread to read from its standard output
            > ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
            > por.Start();
            >
            > proc.StandardIn put.WriteLine ("Hello");
            > proc.StandardIn put.WriteLine ("There");
            > proc.StandardIn put.WriteLine ("quit");
            > }
            >
            > class ProcessOutputRe ader
            > {
            > Process proc;
            >
            > public ProcessOutputRe ader (Process proc)
            > {
            > this.proc = proc;
            > }
            >
            > public void Start()
            > {
            > new Thread (new ThreadStart(Rea dAll)).Start();
            > }
            >
            > void ReadAll()
            > {
            > StreamReader reader = proc.StandardOu tput;
            >
            > string line;
            >
            > while ((line = reader.ReadLine ())!=null)
            > Console.WriteLi ne ("Process output: {0}", line);
            > }
            > }
            > }
            >
            >
            > --
            > Jon Skeet - <skeet@pobox.co m>
            > http://www.pobox.com/~skeet
            > If replying to the group, please do not mail me too[/color]


            Comment

            • Jon Skeet

              #7
              Re: How to execute commands in Command Line?

              Magnus Krisell <magkr747@NOSPA Mstudent.liu.se > wrote:[color=blue]
              > This is interesting.
              > But how do I know if an existing executable writes its output to
              > StandardOutput or StandardError?[/color]

              Experimentation , basically.
              [color=blue]
              > I tried to read the output from the Lame MP3 encoder, and it didn't
              > work at first because it uses StandardError instead of StandardOutput.[/color]

              You could always amalgamate the two - have two threads which each
              listen to one of them and dump the data into a common place (eg an
              ArrayList of the lines read), notifying another thread which reads the
              data.

              Alternatively, have two threads reading the different streams, but
              doing the same thing.

              --
              Jon Skeet - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Madhanmohan S

                #8
                Re: How to execute commands in Command Line?

                Hi Jon,
                I still not able to execute commands in osql process.

                I have attached the code which i am using. Please can you help me out?

                ---------------------------------Code
                Starts --------------------------------------------------
                ProcessStartInf o psi = new ProcessStartInf o(@"osql ","-Usa -PCHETTIAR");
                psi.RedirectSta ndardOutput=tru e;
                psi.RedirectSta ndardInput=true ;
                psi.RedirectSta ndardError=true ;
                psi.UseShellExe cute=false;
                psi.CreateNoWin dow=true;
                Process proc = Process.Start (psi);
                // Start a new thread to read from its standard output
                ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
                por.Start();
                proc.StandardIn put.WriteLine (@"sp_help GO");
                proc.StandardIn put.WriteLine() ;
                try
                {
                //string atrError = proc.StandardEr ror.ReadToEnd() ;
                }
                catch(Exception exc)
                {
                MessageBox.Show (exc.Message);
                }
                proc.StandardIn put.WriteLine ("mohan");
                proc.StandardIn put.WriteLine ("rahul");
                }

                -------------------------------Code
                Ends -------------------------------------------------------

                "Jon Skeet" <skeet@pobox.co m> wrote in message
                news:MPG.19d3a6 792a7269899896e 1@news.microsof t.com...[color=blue]
                > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
                > > I have application which will run in commandline mode. When i[/color][/color]
                start[color=blue][color=green]
                > > the application, it will go to a specific mode (Similar like, when we[/color][/color]
                use[color=blue][color=green]
                > > OSql for MSDE). In this mode, we have to give different commands to[/color][/color]
                execute[color=blue][color=green]
                > > our tasks. I tried with StandardInput Method. But i was not able to[/color][/color]
                execute[color=blue][color=green]
                > > the commands, in the application mode.
                > > When i use the StandardInputMe thod to pass the commands, the C#
                > > application hangs.[/color]
                >
                > Are you reading from StandardOutput and StandardError? Perhaps the
                > other process is blocking.
                >[color=green]
                > > Can you point some resources or sample code for the same???[/color]
                >
                > Sure. First, a very simple echo program:
                >
                > using System;
                >
                > public class Echo
                > {
                > static void Main()
                > {
                > string line;
                > while ((line=Console. ReadLine())!="q uit")
                > Console.WriteLi ne ("Echo: {0}", line);
                > }
                > }
                >
                > Compile it (to echo.exe, as a command-line app) and run it - basically
                > it echoes what you type until you type "quit".
                >
                > Now here's something to automate it:
                >
                > using System;
                > using System.Diagnost ics;
                > using System.IO;
                > using System.Threadin g;
                >
                > public class AutoEcho
                > {
                > static void Main()
                > {
                > ProcessStartInf o psi = new ProcessStartInf o("echo.exe") ;
                > psi.RedirectSta ndardOutput=tru e;
                > psi.RedirectSta ndardInput=true ;
                > psi.UseShellExe cute=false;
                > psi.CreateNoWin dow=true;
                > Process proc = Process.Start (psi);
                >
                > // Start a new thread to read from its standard output
                > ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
                > por.Start();
                >
                > proc.StandardIn put.WriteLine ("Hello");
                > proc.StandardIn put.WriteLine ("There");
                > proc.StandardIn put.WriteLine ("quit");
                > }
                >
                > class ProcessOutputRe ader
                > {
                > Process proc;
                >
                > public ProcessOutputRe ader (Process proc)
                > {
                > this.proc = proc;
                > }
                >
                > public void Start()
                > {
                > new Thread (new ThreadStart(Rea dAll)).Start();
                > }
                >
                > void ReadAll()
                > {
                > StreamReader reader = proc.StandardOu tput;
                >
                > string line;
                >
                > while ((line = reader.ReadLine ())!=null)
                > Console.WriteLi ne ("Process output: {0}", line);
                > }
                > }
                > }
                >
                >
                > --
                > Jon Skeet - <skeet@pobox.co m>
                > http://www.pobox.com/~skeet
                > If replying to the group, please do not mail me too[/color]


                Comment

                • Jon Skeet

                  #9
                  Re: How to execute commands in Command Line?

                  Madhanmohan S <ermadhan@hotma il.com> wrote:[color=blue]
                  > I still not able to execute commands in osql process.
                  >
                  > I have attached the code which i am using. Please can you help me out?[/color]
                  [color=blue]
                  > ---------------------------------Code
                  > Starts --------------------------------------------------
                  > ProcessStartInf o psi = new ProcessStartInf o(@"osql ","-Usa -PCHETTIAR");[/color]

                  First thing: there's nothing in the literal "osql" which suggests it
                  should be a verbatim literal. Just use "osql" without the @.
                  [color=blue]
                  > psi.RedirectSta ndardOutput=tru e;
                  > psi.RedirectSta ndardInput=true ;
                  > psi.RedirectSta ndardError=true ;
                  > psi.UseShellExe cute=false;
                  > psi.CreateNoWin dow=true;
                  > Process proc = Process.Start (psi);
                  > // Start a new thread to read from its standard output
                  > ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
                  > por.Start();
                  > proc.StandardIn put.WriteLine (@"sp_help GO");
                  > proc.StandardIn put.WriteLine() ;
                  > try
                  > {
                  > //string atrError = proc.StandardEr ror.ReadToEnd() ;
                  > }
                  > catch(Exception exc)
                  > {
                  > MessageBox.Show (exc.Message);
                  > }
                  > proc.StandardIn put.WriteLine ("mohan");
                  > proc.StandardIn put.WriteLine ("rahul");
                  > }[/color]

                  Well, is the osql process even starting? You haven't specified where to
                  find it - is it on the path?

                  What happens when you try the code above? You've said it doesn't work,
                  but not what actually happens.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                  If replying to the group, please do not mail me too

                  Comment

                  • Madhanmohan S

                    #10
                    Re: How to execute commands in Command Line?

                    Hi Jon,
                    osql is in system path. I am not able getting any reponse in the
                    reader. The code flows through smoothly with out any output or error.

                    "Jon Skeet" <skeet@pobox.co m> wrote in message
                    news:MPG.19d3bf 878a9bb7139896e 5@news.microsof t.com...[color=blue]
                    > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
                    > > I still not able to execute commands in osql process.
                    > >
                    > > I have attached the code which i am using. Please can you help me out?[/color]
                    >[color=green]
                    > > ---------------------------------Code
                    > > Starts --------------------------------------------------
                    > > ProcessStartInf o psi = new ProcessStartInf o(@"osql ","-Usa -PCHETTIAR");[/color]
                    >
                    > First thing: there's nothing in the literal "osql" which suggests it
                    > should be a verbatim literal. Just use "osql" without the @.
                    >[color=green]
                    > > psi.RedirectSta ndardOutput=tru e;
                    > > psi.RedirectSta ndardInput=true ;
                    > > psi.RedirectSta ndardError=true ;
                    > > psi.UseShellExe cute=false;
                    > > psi.CreateNoWin dow=true;
                    > > Process proc = Process.Start (psi);
                    > > // Start a new thread to read from its standard output
                    > > ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
                    > > por.Start();
                    > > proc.StandardIn put.WriteLine (@"sp_help GO");
                    > > proc.StandardIn put.WriteLine() ;
                    > > try
                    > > {
                    > > //string atrError = proc.StandardEr ror.ReadToEnd() ;
                    > > }
                    > > catch(Exception exc)
                    > > {
                    > > MessageBox.Show (exc.Message);
                    > > }
                    > > proc.StandardIn put.WriteLine ("mohan");
                    > > proc.StandardIn put.WriteLine ("rahul");
                    > > }[/color]
                    >
                    > Well, is the osql process even starting? You haven't specified where to
                    > find it - is it on the path?
                    >
                    > What happens when you try the code above? You've said it doesn't work,
                    > but not what actually happens.
                    >
                    > --
                    > Jon Skeet - <skeet@pobox.co m>
                    > http://www.pobox.com/~skeet
                    > If replying to the group, please do not mail me too[/color]


                    Comment

                    • Jon Skeet

                      #11
                      Re: How to execute commands in Command Line?

                      Madhanmohan S <ermadhan@hotma il.com> wrote:[color=blue]
                      > osql is in system path. I am not able getting any reponse in the
                      > reader. The code flows through smoothly with out any output or error.[/color]

                      So the program is definitely running, and the lines you're poking it
                      with are definitely being executed?

                      Note that using "ReadToEnd" is unlikely to work well as the stream
                      won't end until the process does... that may be the problem you're
                      having. I suggest you read the StandardError stream in the same way as
                      StandardOutput.

                      --
                      Jon Skeet - <skeet@pobox.co m>
                      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                      If replying to the group, please do not mail me too

                      Comment

                      • Madhanmohan S

                        #12
                        Re: How to execute commands in Command Line?


                        "Jon Skeet" <skeet@pobox.co m> wrote in message
                        news:MPG.19d3c9 74613a407d9896e 9@news.microsof t.com...[color=blue]
                        > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green]
                        > > osql is in system path. I am not able getting any reponse in the
                        > > reader. The code flows through smoothly with out any output or error.[/color]
                        >
                        > So the program is definitely running, and the lines you're poking it
                        > with are definitely being executed?[/color]
                        True[color=blue]
                        >
                        > Note that using "ReadToEnd" is unlikely to work well as the stream
                        > won't end until the process does... that may be the problem you're
                        > having. I suggest you read the StandardError stream in the same way as
                        > StandardOutput.[/color]
                        Already I have done the same way as you have suggested. when
                        I gave wrong user name or password, error was properly captured. But when i
                        was very much confussed why the sp_help is not getting executed....... .....
                        Can you suggest any option for checking this or any other way of doing
                        it....[color=blue]
                        >
                        > --
                        > Jon Skeet - <skeet@pobox.co m>
                        > http://www.pobox.com/~skeet
                        > If replying to the group, please do not mail me too[/color]


                        Comment

                        • Jon Skeet

                          #13
                          Re: How to execute commands in Command Line?

                          Madhanmohan S <ermadhan@hotma il.com> wrote:[color=blue][color=green]
                          > > So the program is definitely running, and the lines you're poking it
                          > > with are definitely being executed?[/color]
                          > True[color=green]
                          > >
                          > > Note that using "ReadToEnd" is unlikely to work well as the stream
                          > > won't end until the process does... that may be the problem you're
                          > > having. I suggest you read the StandardError stream in the same way as
                          > > StandardOutput.[/color]
                          > Already I have done the same way as you have suggested. when
                          > I gave wrong user name or password, error was properly captured. But when i
                          > was very much confussed why the sp_help is not getting executed....... .....
                          > Can you suggest any option for checking this or any other way of doing
                          > it....[/color]

                          Sorry, I don't know. Of course, you could always tell osql to write to
                          a file instead, and capture the output afterwards. I don't know if
                          that's okay for you or not though.

                          --
                          Jon Skeet - <skeet@pobox.co m>
                          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                          If replying to the group, please do not mail me too

                          Comment

                          • Madhanmohan S

                            #14
                            Re: How to execute commands in Command Line?

                            Thank You For Your Help.

                            "Jon Skeet" <skeet@pobox.co m> wrote in message
                            news:MPG.19d3cd 2df1af813a9896e d@news.microsof t.com...[color=blue]
                            > Madhanmohan S <ermadhan@hotma il.com> wrote:[color=green][color=darkred]
                            > > > So the program is definitely running, and the lines you're poking it
                            > > > with are definitely being executed?[/color]
                            > > True[color=darkred]
                            > > >
                            > > > Note that using "ReadToEnd" is unlikely to work well as the stream
                            > > > won't end until the process does... that may be the problem you're
                            > > > having. I suggest you read the StandardError stream in the same way as
                            > > > StandardOutput.[/color]
                            > > Already I have done the same way as you have suggested.[/color][/color]
                            when[color=blue][color=green]
                            > > I gave wrong user name or password, error was properly captured. But[/color][/color]
                            when i[color=blue][color=green]
                            > > was very much confussed why the sp_help is not getting[/color][/color]
                            executed....... .....[color=blue][color=green]
                            > > Can you suggest any option for checking this or any other way of doing
                            > > it....[/color]
                            >
                            > Sorry, I don't know. Of course, you could always tell osql to write to
                            > a file instead, and capture the output afterwards. I don't know if
                            > that's okay for you or not though.
                            >
                            > --
                            > Jon Skeet - <skeet@pobox.co m>
                            > http://www.pobox.com/~skeet
                            > If replying to the group, please do not mail me too[/color]


                            Comment

                            • Nick Hertl

                              #15
                              Re: How to execute commands in Command Line?

                              "Madhanmoha n S" <ermadhan@hotma il.com> wrote in message news:<ebNc3qcfD HA.2484@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
                              > Hi All,
                              > I want to run a command line appplication from C#. When i start
                              > the application, it will go into specific mode. After that, i have to give
                              > commands to use the application.
                              > How Can This Be Done in C#....
                              >
                              > Thanks and Regards,
                              > S.Madhanmohan[/color]

                              Something like this should do the trick. Just fill in the places
                              where you want things to happen.

                              using System;

                              class myclass
                              {
                              public static void Main()
                              {
                              init();
                              string command = null;
                              while(true)
                              {
                              Console.Write(" Prompt>");
                              command = Console.ReadLin e();
                              dosomething(com mand);
                              }
                              }
                              private static void init()
                              {}
                              private static void dosomething(str ing input)
                              {}
                              }

                              Comment

                              Working...