Loading ...
Sorry, an error occurred while loading the content.

Clean string returned by windows console cmd

Expand Messages
  • Ni Va
    Hi, I obtain this string that I would like to clean : ^Af D^Ae^Av^Ai^Ac^Ae^AI^AD^A ^A ^A ^AC^A:^A ^A ^A ^A ^A ^A ^A ^A ^A ^AD^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
    Message 1 of 7 , Jul 8, 2014
    • 0 Attachment
      Hi,


      I obtain this string that I would like to clean :

      ^Af><fe>D^Ae^Av^Ai^Ac^Ae^AI^AD^A ^A ^A
      ^AC^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AD^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AE^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AF^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AG^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AH^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AI^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^AZ^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
      ^A




      This is obtained by launching this command :
      echo system("wmic logicaldisk get deviceid")

      I would like to get a list of drives on windows seven :

      C:, D: etc..

      Thank you

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Tim Chase
      ... While shooting from the hip, my first thought would be to do something like echo substitute(system( wmic logicaldisk get deviceid ), [:cntrl:] + , ,
      Message 2 of 7 , Jul 8, 2014
      • 0 Attachment
        On 2014-07-08 09:00, Ni Va wrote:

        > I obtain this string that I would like to clean :
        >
        > ^Af><fe>D^Ae^Av^Ai^Ac^Ae^AI^AD^A ^A ^A
        > ^AC^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AD^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AE^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AF^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AG^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AH^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AI^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^AZ^A:^A ^A ^A ^A ^A ^A ^A ^A ^A
        > ^A
        >
        > This is obtained by launching this command :
        > echo system("wmic logicaldisk get deviceid")
        >
        > I would like to get a list of drives on windows seven :
        >
        > C:, D: etc..

        While shooting from the hip, my first thought would be to do
        something like

        echo substitute(system("wmic logicaldisk get deviceid"),
        '[:cntrl:]\+', '', 'g')

        which should get rid of most of the rubbish.

        -tim


        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • John Beckett
        ... The problem is that the output from wmic is Unicode, and system is dumping the bytes. I don t know how to avoid that, but the ... John -- -- You received
        Message 3 of 7 , Jul 8, 2014
        • 0 Attachment
          Ni Va wrote:
          > This is obtained by launching this command :
          > echo system("wmic logicaldisk get deviceid")

          The problem is that the output from wmic is Unicode, and system
          is dumping the bytes. I don't know how to avoid that, but the
          following reads the plain text if you have the correct settings:

          :r !wmic logicaldisk get deviceid

          John


          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Ni Va
          Hi John, Your command is pretty good but can I affect a variable instead of output command under the cursor into the buffer ... -- -- You received this message
          Message 4 of 7 , Jul 9, 2014
          • 0 Attachment
            Hi John,

            Your command is pretty good but can I affect a variable instead of output command under the cursor into the buffer

            On Wednesday, July 9, 2014 12:16:35 AM UTC+2, JohnBeckett wrote:
            > Ni Va wrote:
            >
            > > This is obtained by launching this command :
            >
            > > echo system("wmic logicaldisk get deviceid")
            >
            >
            >
            > The problem is that the output from wmic is Unicode, and system
            >
            > is dumping the bytes. I don't know how to avoid that, but the
            >
            > following reads the plain text if you have the correct settings:
            >
            >
            >
            > :r !wmic logicaldisk get deviceid
            >
            >
            >
            > John

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • John Beckett
            ... You have to do some work. ... Select the above text and yank it (type yip). Then type :@ to execute the yanked text. The result is that a variable named
            Message 5 of 7 , Jul 9, 2014
            • 0 Attachment
              Ni Va wrote:
              > Your command is pretty good but can I affect a variable
              > instead of output command under the cursor into the buffer

              You have to do some work.

              :new
              :r !wmic logicaldisk get deviceid
              :1,2d
              :%s/\s\+$//e
              :let drives = getline(1,'$')
              :echo drives

              Select the above text and yank it (type yip).
              Then type :@" to execute the yanked text.

              The result is that a variable named drives is a list of the
              drive letters, for example:

              :echo drives
              ['C:', 'D:', 'E:']

              John


              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            • Christian Brabandt
              ... correct. More specifically, the output is - I think - utf-16 (or was it UCS-2?) but instead of leaving the null bytes alone, Vim converts those to SOH
              Message 6 of 7 , Jul 9, 2014
              • 0 Attachment
                Am 2014-07-09 00:16, schrieb John Beckett:
                > Ni Va wrote:
                >> This is obtained by launching this command :
                >> echo system("wmic logicaldisk get deviceid")
                >
                > The problem is that the output from wmic is Unicode, and system
                > is dumping the bytes. I don't know how to avoid that, but the
                > following reads the plain text if you have the correct settings:

                correct. More specifically, the output is - I think - utf-16 (or was it
                UCS-2?)
                but instead of leaving the null bytes alone, Vim converts those to SOH
                (0x01).
                That's why you see all those ^A characters there (plus the BOM in the
                beginning
                of the string, so you can't even convert it on the fly using iconv() or
                such).

                I think Vim should try to convert the output of the system command.
                There is an entry in the todo list about it.

                A simple work around is, to pipe the output through findstr. So this
                should work:

                :echo system("wmic logicaldisk get deviceid|findstr '.*'")

                Alternatively, you might be able to script something using systemlist()
                and iconv()

                Best,
                Christian

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/d/optout.
              • Ni Va
                Thank you everybody. A lot ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
                Message 7 of 7 , Jul 9, 2014
                • 0 Attachment
                  Thank you everybody. A lot

                  On Wednesday, July 9, 2014 2:22:12 PM UTC+2, Christian Brabandt wrote:
                  > Am 2014-07-09 00:16, schrieb John Beckett:
                  >
                  > > Ni Va wrote:
                  >
                  > >> This is obtained by launching this command :
                  >
                  > >> echo system("wmic logicaldisk get deviceid")
                  >
                  > >
                  >
                  > > The problem is that the output from wmic is Unicode, and system
                  >
                  > > is dumping the bytes. I don't know how to avoid that, but the
                  >
                  > > following reads the plain text if you have the correct settings:
                  >
                  >
                  >
                  > correct. More specifically, the output is - I think - utf-16 (or was it
                  >
                  > UCS-2?)
                  >
                  > but instead of leaving the null bytes alone, Vim converts those to SOH
                  >
                  > (0x01).
                  >
                  > That's why you see all those ^A characters there (plus the BOM in the
                  >
                  > beginning
                  >
                  > of the string, so you can't even convert it on the fly using iconv() or
                  >
                  > such).
                  >
                  >
                  >
                  > I think Vim should try to convert the output of the system command.
                  >
                  > There is an entry in the todo list about it.
                  >
                  >
                  >
                  > A simple work around is, to pipe the output through findstr. So this
                  >
                  > should work:
                  >
                  >
                  >
                  > :echo system("wmic logicaldisk get deviceid|findstr '.*'")
                  >
                  >
                  >
                  > Alternatively, you might be able to script something using systemlist()
                  >
                  > and iconv()
                  >
                  >
                  >
                  > Best,
                  >
                  > Christian

                  --
                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/d/optout.
                Your message has been successfully submitted and would be delivered to recipients shortly.