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

Re: Receiving ouput of shell command in vimscript howto

Expand Messages
  • A. J. Mechelynck
    ... You can do it on Unix Vim, see :help backtick-expansion ; but on Windows it s harder (there I guess you d have to use :r ! to read the output of the
    Message 1 of 7 , Mar 2, 2005
    • 0 Attachment
      Shaw Vrana wrote:
      > Hi All,
      >
      > I'd like to hold the output of a shell command in a local variable. I'm
      > trying to do something like this:
      >
      > let myfile = silent exec '!find . -name' myfile
      >
      > Here I'm interested in the output of find, and not the return value of find.
      > (Though I would also be curious to know if I can determine the return value
      > as well, though this isn't essential- I'm sure I'll be wondering how to do
      > that soon enough. ;)
      >
      > :help suggestions greatly appreciated.
      >
      > Thanks,
      > Shaw
      >
      >
      >
      >
      You can do it on Unix Vim, see ":help backtick-expansion"; but on
      Windows it's harder (there I guess you'd have to use ":r !" to read the
      output of the command into a buffer, then yank the buffer into a
      register, from which you can either use it as a variable or ":let" it
      into one).

      HTH,
      Tony
    • Arun Easi
      let myfile=system( find . -name .myfile) ... regards, -Arun
      Message 2 of 7 , Mar 2, 2005
      • 0 Attachment
        let myfile=system('find . -name '.myfile)

        :he system
        :he v:shell_error

        regards,
        -Arun

        On Wed, 2 Mar 2005, Shaw Vrana wrote:

        > Hi All,
        >
        > I'd like to hold the output of a shell command in a local variable. I'm
        > trying to do something like this:
        >
        > let myfile = silent exec '!find . -name' myfile
        >
        > Here I'm interested in the output of find, and not the return value of find.
        > (Though I would also be curious to know if I can determine the return value
        > as well, though this isn't essential- I'm sure I'll be wondering how to do
        > that soon enough. ;)
        >
        > :help suggestions greatly appreciated.
        >
        > Thanks,
        > Shaw
        >
        >
      • Gary Johnson
        ... That s what I usually do, too, except that I also use substitute() to remove the trailing newline from the output: let myfile=substitute(system( find .
        Message 3 of 7 , Mar 2, 2005
        • 0 Attachment
          On 2005-03-02, Arun Easi <aeasi@...> wrote:

          > On Wed, 2 Mar 2005, Shaw Vrana wrote:

          > > I'd like to hold the output of a shell command in a local variable. I'm
          > > trying to do something like this:
          > >
          > > let myfile = silent exec '!find . -name' myfile
          > >
          > > Here I'm interested in the output of find, and not the return value of find.
          > > (Though I would also be curious to know if I can determine the return value
          > > as well, though this isn't essential- I'm sure I'll be wondering how to do
          > > that soon enough. ;)
          > >
          > > :help suggestions greatly appreciated.

          > let myfile=system('find . -name '.myfile)

          That's what I usually do, too, except that I also use substitute()
          to remove the trailing newline from the output:

          let myfile=substitute(system('find . -name '.myfile), "\n", "", "")

          :help substitute()

          HTH,
          Gary

          --
          Gary Johnson | Agilent Technologies
          garyjohn@... | Wireless Division
          | Spokane, Washington, USA
        • Shaw Vrana
          ... A bunch of helpful answers here. I had not known of the system command- this will come in very handy. Thanks you all for helping me further along the
          Message 4 of 7 , Mar 2, 2005
          • 0 Attachment
            > On 2005-03-02, Arun Easi <aeasi@...> wrote:
            > let myfile=substitute(system('find . -name '.myfile), "\n", "", "")

            A bunch of helpful answers here. I had not known of the 'system' command-
            this will come in very handy. Thanks you all for helping me further along
            the learning curve!

            The system() call is mentioned in chapter 27 of Qualine's good Vim book, but I
            apparently cannot read. :(

            Thanks,
            Shaw
          • jamessan@jamessan.com
            ... That may (and probably does) have functions that aren t listed in the Vim book. James -- GPG Key: 1024D/61326D40 2003-09-02 James Vega
            Message 5 of 7 , Mar 2, 2005
            • 0 Attachment
              On Wed, Mar 02, 2005 at 11:46:41AM -0800, Shaw Vrana wrote:
              > > On 2005-03-02, Arun Easi <aeasi@...> wrote:
              > > let myfile=substitute(system('find . -name '.myfile), "\n", "", "")
              >
              > A bunch of helpful answers here. I had not known of the 'system' command-
              > this will come in very handy. Thanks you all for helping me further along
              > the learning curve!
              >
              > The system() call is mentioned in chapter 27 of Qualine's good Vim book, but I
              > apparently cannot read. :(

              You can also access an alphabetical list of functions via:

              :help functions

              or grouped by what they're used for:

              :help function-list

              That may (and probably does) have functions that aren't listed in the
              Vim book.

              James

              --
              GPG Key: 1024D/61326D40 2003-09-02 James Vega <jamessan@...>
            Your message has been successfully submitted and would be delivered to recipients shortly.