我想在python脚本中调用一个编辑器来征求用户的意见,就像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 )
Run Code Online (Sandbox Code Playgroud)
我的问题是,通过使用Popen,它似乎让我的i/o与python脚本进入vim的运行副本,我找不到一种方法来将i/o传递给vim.我收到以下错误.
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
Run Code Online (Sandbox Code Playgroud)
什么是从python调用CLI程序,手动控制到它的最佳方法,然后在完成后将其传回去?