如何在编辑器中通过管道输出程序?
我的程序生成一些数据。它以标准错误输出所有内容。
现在我想将输出重定向到新启动的文本编辑器,进入启动时显示的主未命名编辑窗口。我尝试使用 vim 和 gedit 但没有成功。
myprogram | gedit
myprogram | gvim
有人知道支持此功能的 X11 文本编辑器吗?
I have my program generating some data. It output everything on standard error.
Now I'd like to redirect the output to a newly started text editor, into the main unnamed edit window that shows at startup. I tried with vim and gedit without success.
myprogram | gedit
myprogram | gvim
Anyone knows about an X11 text editor that would support this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果你想将程序的
stderr
重定向到gvim
你可以这样做:如果你想将
stdout
重定向到编辑器你可以这样做:If you want to redirect
stderr
of your program in togvim
you can do:and in case if you want to redirect the
stdout
to the editor you can do:我在 Ubuntu 12.04 中尝试过此操作,它按预期工作:
在 Ubuntu 14.04
Dimitry K 上于 16 年 1 月 22 日 19:00 添加了以下内容,
我认为您仍然需要破折号:(
尝试了 ubuntu 14.04,只有破折号才有效) –
I tried this in Ubuntu 12.04, it works as desired:
On Ubuntu 14.04
Dimitry K added on Jan 22 '16 at 19:00 the following
I think you still need dash after:
(tried ubuntu 14.04 and only with dash it works) –
要使用任何编辑器在一行中完成这一切,请创建一个临时文件,使用 gedit 打开它,然后在 gedit 打开它后将其删除:
echo hello >温度; gedit 温度;睡眠 1 && rm temp &
以下内容适用于 vim 等编辑器,但 gedit、geany 或 emacs 似乎无法打开由 <( )
vi <( echo 创建的标准输入或临时文件你好)
回声你好 | vi-
To do this all in one line with any editor, create a temporary file, open it with gedit, then delete it once gedit has it open:
echo hello > temp ; gedit temp ; sleep 1 && rm temp &
The following works with an editor such as vim, but gedit, geany or emacs seem to be unable to open standard input or temporary files as created by <( )
vi <( echo hello )
echo hello | vi -
我不知道有哪个编辑器支持此功能,但重定向到临时文件可能会更容易。
I don't know of any editor that supports this, but redirecting to a temp file might be easier.
我最喜欢的编辑器:-)
正如已经说过的,当程序不支持此类管道时,最好的方法是使用目录 /tmp/ 中的临时文件,该文件通常会在下次启动时删除。
my favorite editor :-)
As already said, when a program does not support such piping, the best way is to use a temporal file in the directory /tmp/ which is usually deleted at the next boot.
vipe
这样做是为了任意$EDITOR
,可通过brew install moreutils
在 macOS /homebrew 上使用vipe
does this for an arbitrary$EDITOR
, available on macOS /homebrew viabrew install moreutils