【发布时间】:2011-06-10 16:48:40
【问题描述】:
我想在 python 脚本中调用一个编辑器来征求用户的输入,就像 crontab e 或 git commit 所做的那样。
这是我目前运行的一个 sn-p。 (将来,我可能会使用 $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 脚本无法进入 vim 的运行副本,我找不到将 i/o 传递给 vim 的方法.我收到以下错误。
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
从 python 调用 CLI 程序、将控制权交给它并在完成后将其传回的最佳方法是什么?
【问题讨论】:
标签: python vim editor command-line-interface