Я хочу вызвать редактор в python script для запроса ввода от пользователя, как это делают crontab e
или git commit
.
Вот фрагмент из того, что у меня есть. (В будущем я могу использовать $EDITOR вместо vim, чтобы люди могли настроить их по своему вкусу.)
tmp_file = '/tmp/up.'+''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
edit_call = [ "vim",tmp_file]
edit = subprocess.Popen(edit_call,stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )
Моя проблема заключается в том, что, используя Popen, мне кажется, что мой i/o с python script не попадает в текущую копию vim, и я не могу найти способ просто передать i/o через к vim. Я получаю следующую ошибку.
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
Какой лучший способ вызвать CLI-программу из python, передать ее вручную, а затем передать ее после того, как вы закончите с ней?