Alignment of command prompt output of remote server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vel
    New Member
    • Oct 2007
    • 12

    Alignment of command prompt output of remote server

    Hi,

    My program is access the remote system's command prompt through C# program. I can do it. But problem is alignment of that output.
    can any one give idea to align that output ?.


    here is my code........... ...........



    try
    {
    SshShell ssh1 = new SshShell(host,u ser,pass);

    SshStream ssh = new SshStream(host, user, pass);
    Console.WriteLi ne("------Connecting...") ;
    ssh1.Connect();
    Console.Write(" OK");
    Console.WriteLi ne();
    //ssh.Prompt ="$";

    ssh1.RemoveTerm inalEmulationCh aracters = true;
    Console.Write(s sh1.Expect("$") );
    //ssh1.Expect("$" );
    while (true)
    {
    Console.Write(" Ent the cmd:");
    string command = Console.ReadLin e();
    if (command.ToLowe r().Equals("exi t"))
    break;
    ssh1.WriteLine( command);
    string out1 = ssh1.Expect(">" );
    out1 = out1.Replace(" ", "\n ");
    out1 = "\n" + out1;
    Console.WriteLi ne(out1);
    //Console.WriteLi ne(ssh1.Expect( ">"));

    }
    ssh1.Close();
    ssh.Close();
    Console.WriteLi ne("Connection closed.");

    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What do you mean by alignment?

    Comment

    • vel
      New Member
      • Oct 2007
      • 12

      #3
      Originally posted by Plater
      What do you mean by alignment?


      Thanks for your reply.


      The output should be appear as same that of command prompt window output(line by line). eg:1) First Line......
      2)Second Line.......and so on
      Now it prints
      as shown below.
      eg: 1)First Line......2)Sec ond Line.......3) and so on...

      it use the full length of the output screen.after that only it comes to 2nd line..

      Comment

      • vel
        New Member
        • Oct 2007
        • 12

        #4
        Hi,


        when we use dir,ipconfig command the outputs are in multi line. Is it ?
        i have to align that output as it showing in command prompt.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          newlines are "\r\n", if that helps.
          Although Console.WriteLi ne() should have created a "newline" for you. Odd

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Try reading the response with

            [CODE=cpp] String output = ssh1.ReadRespon se();[/CODE]

            Comment

            • vel
              New Member
              • Oct 2007
              • 12

              #7
              thanks for your reply.
              Ya, I tried it.


              I need the Output in the following format.

              ---------------------------------------------------------------
              C:\Documents and Settings\udhaya .k>dir
              Volume in drive C has no label.
              Volume Serial Number is A421-E76F

              Directory of C:\Documents and Settings\udhaya .k

              11/22/2006 12:04 PM <DIR> .
              11/22/2006 12:04 PM <DIR> ..
              02/09/2007 12:18 PM 175 .jlogon9
              03/05/2007 06:11 PM 1,403 .isqlHistory9
              10/24/2007 05:30 PM 1,846 .bookmarks
              06/02/2006 11:10 AM <DIR> Start Menu
              12/15/2006 12:50 PM <DIR> My Documents 19 File(s) 258,099 bytes
              15 Dir(s) 12,946,948,096 bytes free
              ------------------------------------------------------------------------------------------


              But in console Application it printed in following format:
              --------------------------------------------------------------------------------
              C:\Documents and Settings\udhaya .k>dirVolume in drive C has no label.Volume Serial Number is A421-E76 Directory of C:\Documents and Settings\udhaya .k11/22/2006 12:04 PM <DIR> .11/22/2006 12:04 PM <DIR> ..02/09/2007 12:18 PM 175 .jlogon903/05/2007 06:11 PM 1,403 .isqlHistory910/24/2007 05:30 PM 1,846 .bookmarks06/02/2006 11:10 AM <DIR> Start Menu
              12/15/2006 12:50 PM <DIR> My Documents 19 File(s) 258,099 bytes
              15 Dir(s) 12,946,948,096 bytes free
              ---------------------------------------------------------------------------------------------------------------


              Now can you get it off my problem?. The stream prints the output continuously.



              Originally posted by Plater
              newlines are "\r\n", if that helps.
              Although Console.WriteLi ne() should have created a "newline" for you. Odd

              Comment

              • vel
                New Member
                • Oct 2007
                • 12

                #8
                thanks for your reply.
                Ya, I tried it.


                I need the Output in the following format.This is the cmd prompt output.

                ---------------------------------------------------------------
                C:\Documents and Settings\udhaya .k>dir
                Volume in drive C has no label.
                Volume Serial Number is A421-E76F

                Directory of C:\Documents and Settings\udhaya .k

                11/22/2006 12:04 PM <DIR> .
                11/22/2006 12:04 PM <DIR> ..
                02/09/2007 12:18 PM 175 . jlogon9
                03/05/2007 06:11 PM 1,403 .isqlHistory9
                10/24/2007 05:30 PM 1,846 .bookmarks
                06/02/2006 11:10 AM <DIR> Start Menu
                12/15/2006 12:50 PM <DIR> My Documents
                19 File(s) 258,099 bytes
                15 Dir(s) 12,946,948,096 bytes free
                ------------------------------------------------------------------------------------------


                But in console Application it printed in following format:
                --------------------------------------------------------------------------------
                C:\Documents and Settings\udhaya .k>dirVolume in drive C has no label.Volume Serial Number is A421-E76 Directory of C:\Documents and Settings\udhaya .k11/22/2006 12:04 PM <DIR> .11/22/2006 12:04 PM <DIR> ..02/09/2007 12:18 PM 175 .jlogon903/05/2007 06:11 PM 1,403 .isqlHistory910/24/2007 05:30 PM 1,846 .bookmarks06/02/2006 11:10 AM <DIR> Start Menu
                12/15/2006 12:50 PM <DIR> My Documents 19 File(s) 258,099 bytes
                15 Dir(s) 12,946,948,096 bytes free
                ---------------------------------------------------------------------------------------------------------------


                Now can you get it off my problem?. The stream prints the output continuously.
                Please Try my code.


                Originally posted by Plater
                newlines are "\r\n", if that helps.
                Although Console.WriteLi ne() should have created a "newline" for you. Odd

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by vel
                  thanks for your reply.
                  Ya, I tried it.


                  I need the Output in the following format.This is the cmd prompt output.

                  ---------------------------------------------------------------
                  C:\Documents and Settings\udhaya .k>dir
                  Volume in drive C has no label.
                  Volume Serial Number is A421-E76F

                  Directory of C:\Documents and Settings\udhaya .k

                  11/22/2006 12:04 PM <DIR> .
                  11/22/2006 12:04 PM <DIR> ..
                  02/09/2007 12:18 PM 175 . jlogon9
                  03/05/2007 06:11 PM 1,403 .isqlHistory9
                  10/24/2007 05:30 PM 1,846 .bookmarks
                  06/02/2006 11:10 AM <DIR> Start Menu
                  12/15/2006 12:50 PM <DIR> My Documents
                  19 File(s) 258,099 bytes
                  15 Dir(s) 12,946,948,096 bytes free
                  ------------------------------------------------------------------------------------------


                  But in console Application it printed in following format:
                  --------------------------------------------------------------------------------
                  C:\Documents and Settings\udhaya .k>dirVolume in drive C has no label.Volume Serial Number is A421-E76 Directory of C:\Documents and Settings\udhaya .k11/22/2006 12:04 PM <DIR> .11/22/2006 12:04 PM <DIR> ..02/09/2007 12:18 PM 175 .jlogon903/05/2007 06:11 PM 1,403 .isqlHistory910/24/2007 05:30 PM 1,846 .bookmarks06/02/2006 11:10 AM <DIR> Start Menu
                  12/15/2006 12:50 PM <DIR> My Documents 19 File(s) 258,099 bytes
                  15 Dir(s) 12,946,948,096 bytes free
                  ---------------------------------------------------------------------------------------------------------------


                  Now can you get it off my problem?. The stream prints the output continuously.
                  Please Try my code.
                  So ssh1.ReadRespon se() did not work as well?

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Are you removing your line breaks? Where are the "\r\n" ?

                    Comment

                    • vel
                      New Member
                      • Oct 2007
                      • 12

                      #11
                      Originally posted by Plater
                      Are you removing your line breaks? Where are the "\r\n" ?

                      Oh! Thanks for your Help....
                      and I tried that too...
                      but i not coming...Anyway
                      I completed that task.....

                      Comment

                      Working...