1

Say if I wanted to run vim ./foo.txt I want to be able to edit foo.txt with my tcp socket client.

But whenever I try to do this it executes on the server but not on my client.

I do not want to use paramiko or any other ssh-like modules I want to stay using the python socket module.

I am using python 3.

  • You'll need to find a way to get your keypresses on the client, over to the server, and then into vim. And to get vim's display output back to the client and display it. – user253751 Feb 03 '18 at 23:34

1 Answers1

0

I would suggest opening a command on the server (where the file is) with the subprocess module. This way to can keep putting information into it. You can have the client send a message which tells the server to send x to the subprocess.

An example would be like this:

import subprocess

# Assuming the variable x is that the socket is sending the server...
editing_foo = subprocess.Popen(['vim', './foo.txt'], stdin=PIPE)  # stdin must be PIPE to communicate
editing_foo.communicate(input=x)  # input is a string which is sent to the subprocess
# x could have been 'i' or ':q!' for example
purple_dot
  • 106
  • 2
  • 9
  • When I run this it says PIPE is undefined any answer? –  Feb 04 '18 at 22:19
  • Cool! I'm happy I could help. Check out the [subprocess](https://docs.python.org/3/library/subprocess.html) documentation page on the Python website for more info about the module. – purple_dot Feb 04 '18 at 22:42