I'm trying to open a file with vanilla vi (/usr/bin/vi on Solaris 10) from a Python (2.6.4) script, and nothing I do seems to be working. I want to have the script put some data in a temporary file, then open that file in vi for the user to edit. Ideally the script would block on the call to vi and continue executing when the user is finished, but I could settle for solutions transforming the script process into the vi process (via exec or something).
I've tried the following, but for each of them vi prints the first page of the file to the screen and then exits with a "Input read error":
os.execlp('vi', 'vi', filename)
os.system('vi' + ' ' + filename)
subprocess.call('vi' + ' ' + filename, shell=True)
For context, here is the code in its entirety:
#!/usr/bin/python
import sys
import os
import subprocess
fname = "." + str(os.getpid()) + ".pvi.tmp"
f = open(fname, 'w')
f.write("## Remember to save this to a new file if you want to keep it!\n")
for line in sys.stdin:
f.write(line + "\n")
f.close()
# These all give the error "Input read error"
#os.execlp('vi', 'vi', fname)
#os.system('vi' + ' ' + fname)
#subprocess.call('vi' + ' ' + fname, shell=True)
os.unlink(fname)
I'm basically trying to emulate piping processes into vi, which my version doesn't support (vi - doesn't work). I would pipe them to this script which would then write the output to a temporary file and open it in vi.
Any help would be much appreciated!
vi filename, instead of running the Python script? Is$TERMset correctly for your terminal?vi filenameworks as expected. My$TERMis set to xterm, which I believe is correct. I'm running the script (called pvi) asecho "asdf" | pvi.echoinstead of a terminal.