Connect Console with Python using Subprocess

PyVim is written for a while, during the writing code, there indeed a lot of problems.

I try to implement the buffer for a console ( now just on Windows ) , but i find that the subprocess using for the communication for the process has a problem with “communicate” function.

It will close the input/output function if you once using the “communicate” function.

So there just another way to do it .

  1. import subprocess
  2. cmd_ins = subprocess.Popen(
  3. ‘cmd.exe’ ,
  4. stdin = subprocess.PIPE ,
  5. stdout = subprocess.PIPE ,
  6. stderr = subprocess.STDOUT ,
  7. shell = True )
  8. def Run( output , filename ):
  9. file_handle = open( filename , ‘a+’ )
  10. while True :
  11. file_handle.write( output.readline() )
  12. file_handle.flush()
  13. import threading
  14. t = threading.Thread( target = Run , args = ( cmd_ins.stdout , ‘D:\\output.txt’ ) )
  15. t.start()
  16. while True :
  17. print >> cmd_ins.stdin , raw_input(“> “)

just a emulation for connecting to the console , and you can modify the code as you wish.
PyVim is going on ~~

Advertisements