trouble controlling vim with subprocess on windows machine

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric_Dexter@msn.com

    trouble controlling vim with subprocess on windows machine

    I am having trouble contolling vim with subprocess on a windows
    machine. It appears that vim comes up on the machine all right and it
    sometimes looks like it is doing the searchs what I am asking it to do
    but when I am asking it to load a file it doesn't do anything. Is
    there something I need to do to push the data through the pipe?? Here
    is a couple different ways I am trying to do it.

    def load_instrument (instr_name, csdname):
    "load an instrument using vim a path should be defined for vim
    currently I am doing that with the .bat file that loads the program"
    f = open('csdfile.t mp','w')
    my_path = "/dex tracker"
    cmd = ["gvim",csdn ame]
    vimin = subprocess.Pope n(cmd,stdin=sub process.PIPE)#. comunicate()
    [0] #, stdout = f, stderr = f, cwd = my_path )
    #f.close
    #x = subprocess.Pope n("clear").comm unicate(None)[0]
    innum = csr.return_uniq ue_instr_number (csdname) - 1
    cmd = """/;<start""" + str(innum) + '>' +'\n'
    print(cmd)
    vimin.stdin.wri te(cmd)
    cmd = """/;<endin>""" +'\n'
    vimin.stdin.com municate(cmd)
    cmd = ':r ' + instr_name +'\n'
    print(cmd)
    vimin.stdin.wri te(cmd)
    #vimin.stdin.wr ite(instr_name + '\n')
    cmd = instr_name + '\n'

    f.close()
    def load_instrument 2(instr_name, csdname):
    "second try uses comunicate"
    cmd = ["gvim",csdn ame]
    proc = subprocess.Pope n(cmd, shell=True, stdin=subproces s.PIPE, )
    cmd = """/;start""" + '\n'
    proc.communicat e(cmd)[0]
    cmd = """/;<endin>""" + '\n'
    proc.communicat e(cmd)[0]
    cmd = ':r ' + instr_name + '/n'
    proc.communicat e(cmd)[0]
    proc.close()

    I am calling these with

    load_instrument 2("""strings.or c""",'bay-at-night.csd')

    and I define the path of vim in a batch file befour I call the
    routines

    path c:\program files\vim\vim71
    python_awk_brid ge.py
    pause

  • Nick Craig-Wood

    #2
    Re: trouble controlling vim with subprocess on windows machine

    Eric_Dexter@msn .com <Eric_Dexter@ms n.comwrote:
    I am having trouble contolling vim with subprocess on a windows
    machine. It appears that vim comes up on the machine all right and it
    sometimes looks like it is doing the searchs what I am asking it to do
    but when I am asking it to load a file it doesn't do anything. Is
    there something I need to do to push the data through the pipe?? Here
    is a couple different ways I am trying to do it.
    For controlling an interactive program subprocess isn't the right
    tool. Subprocess only really does one way communication - it isn't
    good at conversations. I'd suggest pexpect but it doesn't work on
    windows.

    You appear to be doing stuff with csound. There are several python
    modules out there which interface with csound - did you investigate
    those?

    --
    Nick Craig-Wood <nick@craig-wood.com-- http://www.craig-wood.com/nick

    Comment

    • Eric_Dexter@msn.com

      #3
      Re: trouble controlling vim with subprocess on windows machine

      On Jul 9, 5:30 am, Nick Craig-Wood <n...@craig-wood.comwrote:
      Eric_Dex...@msn .com <Eric_Dex...@ms n.comwrote:
      I am having trouble contolling vim with subprocess on a windows
      machine. It appears that vim comes up on the machine all right and it
      sometimes looks like it is doing the searchs what I am asking it to do
      but when I am asking it to load a file it doesn't do anything. Is
      there something I need to do to push the data through the pipe?? Here
      is a couple different ways I am trying to do it.
      >
      For controlling an interactive program subprocess isn't the right
      tool. Subprocess only really does one way communication - it isn't
      good at conversations. I'd suggest pexpect but it doesn't work on
      windows.
      >
      You appear to be doing stuff with csound. There are several python
      modules out there which interface with csound - did you investigate
      those?
      >
      --
      Nick Craig-Wood <n...@craig-wood.com--http://www.craig-wood.com/nick
      The book (as kramer would say)

      Download Dex Tracker for free. tracker interface for csound. working sco editor, drum machine exc, support for vst and csound instruments.


      I would think that the purpose for stdin is input and stdout is
      output.. otherwise why have stdin?? The pyexpect does look like what
      I am after but it isn't windows.. And did I mention I am willing to
      cheat I have a large number of unix tools that are converted over (but
      not cigwin) and will even be willing to generate a script file if I
      can get it to vim when it starts up... whatever it takes regardless
      of how ugly looking it is.

      I did notice expect




      I am not sure what to do to call the tcl stuff from python though.

      Comment

      • Josiah Carlson

        #4
        Re: trouble controlling vim with subprocess on windows machine

        Eric_Dexter@msn .com wrote:
        I am having trouble contolling vim with subprocess on a windows
        machine. It appears that vim comes up on the machine all right and it
        sometimes looks like it is doing the searchs what I am asking it to do
        but when I am asking it to load a file it doesn't do anything. Is
        there something I need to do to push the data through the pipe?? Here
        is a couple different ways I am trying to do it.
        [snip]

        This recipe for asynchronous communication using subprocess could be
        used to write an expect-like tool:


        It works on both Windows and *nix.


        - Josiah

        Comment

        • Eric_Dexter@msn.com

          #5
          Re: trouble controlling vim with subprocess on windows machine

          On Jul 9, 11:06 am, Josiah Carlson <josiah.carl... @sbcglobal.net>
          wrote:
          Eric_Dex...@msn .com wrote:
          I am having trouble contolling vim with subprocess on a windows
          machine. It appears that vim comes up on the machine all right and it
          sometimes looks like it is doing the searchs what I am asking it to do
          but when I am asking it to load a file it doesn't do anything. Is
          there something I need to do to push the data through the pipe?? Here
          is a couple different ways I am trying to do it.
          >
          [snip]
          >
          This recipe for asynchronous communication using subprocess could be
          used to write an expect-like tool:

          >
          It works on both Windows and *nix.
          >
          - Josiah
          I had the original dir work but when I tried to trade it out with vim
          it isn't clear
          how I should call it.. vim filename and it doesn't find filename for
          some reason.
          I called it pipe and then


          inport pipe

          def load_instrument 3(instr_name, csd_name):
          if sys.platform == 'win32':
          shell, commands, tail = ('gvim' + csd_name, (csd_name,
          csd_name), '\r\n')
          else:
          shell, commands, tail = ('sh', ('ls', 'echo HELLO WORLD'),
          '\n')

          a = pipe.Popen(shel l, stdin=pipe.PIPE , stdout=pipe.PIP E)
          print pipe.recv_some( a),
          for cmd in commands:
          pipe.send_all(a , csd_name)
          print pipe.recv_some( a),
          pipe.send_all(a , csd_name)
          print pipe.recv_some( a, e=0)
          a.wait()


          Comment

          • Josiah Carlson

            #6
            Re: trouble controlling vim with subprocess on windows machine

            agc wrote:
            Hi Josiah,
            >
            >>>This recipe for asynchronous communication usingsubprocess could be
            >>>used to write an expect-like tool:
            >>> http://aspn.activestate.com/ASPN/Coo.../Recipe/440554
            >
            I have played with the above recipe and it is excellent,
            but could you please go into some more detail about what is needed
            to make a cross platform [p]expect like (non-pty based) tool?
            We only get ptys. Unless you can figure out some incantation to fake
            the creation of a tty (so that ssh and other software don't conmplain),
            all you get is a pty.

            To make it work like expect, one would (strictly speaking) need to do
            the pattern matching that expect does, which may require writing a new
            regular expression library.

            Specifically, could you describe how you would connect to
            *another* interactive Python process with your subclass of
            subprocess.Pope n?
            i.e:
            >
            a = Popen('python', stdin=?, stdout=?, stderr=?)
            #now run an interactive session with 'a'
            Some platforms have very strange buffering behavior with Python. What I
            have done in my own code (for creating a Python subprocess, though not
            using the subprocess module) is to do something like the following...

            python_cmd = '''<path to python-u -c "import sys; \
            sys.stderr=sys. __stderr__=sys. stdout;import __builtin__;\
            __builtin__.qui t=__builtin__.e xit=\
            'use Ctrl-Break to restart *this* interpreter';im port code;\
            code.interact(r eadfunc=raw_inp ut)"'''

            a = Popen(python_cm d, subprocess.PIPE , subprocess.PIPE )
            I have tried several combinations of the above and I seem
            to be stuck on the fact that python is interacting with a
            'tty', not 'std*'. Maybe I'm missing a basic piece?
            I've had buffering issues on certain platforms (Windows), error messages
            about not having a tty (when trying to control an ssh session on *nix
            and Windows), etc. Getting this to work for arbitrary programs that
            expect a tty, and/or being able to query the terminal for other
            information (dimension, terminal emulation, etc.), will be a chore, if
            not impossible.


            - Josiah

            Comment

            • Eric_Dexter@msn.com

              #7
              Re: trouble controlling vim with subprocess on windows machine

              On Jul 16, 7:45 am, Yves Pouplard <yves.poupl...@ free.frwrote:
              On Mon, 09 Jul 2007 05:30:04 -0500, Nick Craig-Wood
              >
              <n...@craig-wood.comwrote:
              Eric_Dex...@msn .com <Eric_Dex...@ms n.comwrote:
              I am having trouble contolling vim with subprocess on a windows
              machine. It appears that vim comes up on the machine all right and it
              sometimes looks like it is doing the searchs what I am asking it to do
              but when I am asking it to load a file it doesn't do anything. Is
              there something I need to do to push the data through the pipe?? Here
              is a couple different ways I am trying to do it.
              >
              For controlling an interactive program subprocess isn't the right
              tool. Subprocess only really does one way communication - it isn't
              good at conversations. I'd suggest pexpect but it doesn't work on
              windows.
              >
              pexpect works with Cygwin's python :)
              >
              >
              >
              You appear to be doing stuff withcsound. There are several python
              modules out there which interface withcsound- did you investigate
              those?- Hide quoted text -
              >
              - Show quoted text -
              I managed to get it as a com object (they have an example that isn't
              very good on the gvim site) and it is in csound routines as of 2pm
              today... Looks like it should be easy to do with sed also but I don't
              know that much about it.

              Comment

              Working...