作者Holocaust123 (奔跑的蜗牛)
看板Editor
标题[vim ] 如何在执行外部指令时不冻结vim
时间Sun Jan 9 16:35:56 2011
举个例子
:!python foo.py
在vim中用上述指令执行foo.py这支程式
foo.py在执行时vim会freeze(游标什麽的都不能动)
要等到foo.py结束才能使用vim
这问题在Windows下可以这样解:
http://vim.wikia.com/wiki/Execute_external_programs_asynchronously_under_Windows
(:!start cmd /c python foo.py & pause<CR> )
但在Linux下这解法似乎没用
请问有人知道该怎麽办吗 谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.32
1F:推 dryman:!python foo.py & 这样? 01/09 20:02
似乎不行耶...附上程式码 & 错误讯息
// foo.py
input = raw_input('input something:')
print 'you input:' + input
:!python % 没问题, 但
:!python % &会有错误(看不太懂...):
// output
input something:Traceback (most recent call last):
File "foo.py", line 1, in <module>
input = raw_input('input something:')
EOFError: EOF when reading a line
Press ENTER or type command to continue
// 截图
http://www.dumpt.com/img/viewer.php?file=qmtq01aq80gl2w1pfho1.jpg
2F:→ yoco315:你的外部指令正打算从 stdin 读东西耶.. 01/09 21:23
3F:→ yoco315:你让他在背景跑 请问你要他读什麽 @@? 01/09 21:23
4F:→ Holocaust123:对吼...我在干嘛~"~ 01/09 21:27
5F:→ kornelius:改成使用 system 然後 pipe 到 log file 01/10 10:10
6F:→ kornelius:再用 tail -f logfile 就很好用了。 01/10 10:11
7F:→ kornelius:写个 script 包起来,自动喂 stdin 01/10 10:11
谢谢版主大人~
我试了一个下午
想到一个不需写script喂stdin的方法:
:!screen bash -c "python \"%\" ; read -p \"press any key to continue...\""
※ 编辑: Holocaust123 来自: 140.112.30.32 (01/10 18:25)
8F:推 dryman:也可以预先把要stdin的东西弄成一个档,然後pipe进去 01/10 19:23
9F:推 letoh:弄个 fifo 应该也很方便? mkfifo 01/16 17:03