Linux 如何在编辑器中管道程序输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3864814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pipe program output in an editor?
提问by Didier Trosset
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.
现在我想将输出重定向到一个新启动的文本编辑器,进入在启动时显示的主要未命名编辑窗口。我尝试使用 vim 和 gedit 没有成功。
myprogram | gedit
myprogram | gvim
Anyone knows about an X11 text editor that would support this?
有人知道支持此功能的 X11 文本编辑器吗?
采纳答案by codaddict
If you want to redirect stderr
of your program in to gvim
you can do:
如果您想将stderr
您的程序重定向到gvim
您可以执行以下操作:
myprogram 2>&1 | gvim -
and in case if you want to redirect the stdout
to the editor you can do:
如果您想将 重定向stdout
到编辑器,您可以执行以下操作:
myprogram| gvim -
回答by Douglas Leeder
I don't know of any editor that supports this, but redirecting to a temp file might be easier.
我不知道有任何支持此功能的编辑器,但重定向到临时文件可能更容易。
F=$(mktemp)
myprogram >$F
gedit $F
rm $F
回答by RoboJ1M
I tried this in Ubuntu 12.04, it works as desired:
我在 Ubuntu 12.04 中尝试过这个,它按预期工作:
sudo lshw | gedit &
On Ubuntu 14.04
在 Ubuntu 14.04 上
sudo lshw | gedit - &
Dimitry Kadded on Jan 22 '16 at 19:00the following
Dimitry K于2016年1 月 22 日 19:00 添加了以下内容
I think you still need dash after:
我认为你仍然需要破折号:
gedit sudo lshw | gedit - &
(tried ubuntu 14.04 and only with dash it works) –
(试过 ubuntu 14.04,只有 dash 才有效) –
回答by Brendan Cody-Kenny
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:
要使用任何编辑器在一行中完成所有操作,请创建一个临时文件,使用 gedit 打开它,然后在 gedit 打开后将其删除:
echo hello > temp ; gedit temp ; sleep 1 && rm temp &
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 <( )
以下内容适用于 vim 等编辑器,但 gedit、geany 或 emacs 似乎无法打开由 <( ) 创建的标准输入或临时文件
vi <( echo hello )
vi <( echo hello )
echo hello | vi -
echo hello | vi -
回答by xerostomus
history | kate -i
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.
如前所述,当程序不支持这种管道时,最好的方法是使用目录 /tmp/ 中的临时文件,该文件通常在下次启动时删除。
history > /tmp/bflmpsvz;mcedit /tmp/bflmpsvz