如何在编辑器中通过管道输出程序?

发布于 2024-09-26 01:00:11 字数 194 浏览 0 评论 0原文

我的程序生成一些数据。它以标准错误输出所有内容。

现在我想将输出重定向到新启动的文本编辑器,进入启动时显示的主未命名编辑窗口。我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

z祗昰~ 2024-10-03 01:00:11

如果你想将程序的 stderr 重定向到 gvim 你可以这样做:

myprogram 2>&1 | gvim -

如果你想将 stdout 重定向到编辑器你可以这样做:

myprogram| gvim -

If you want to redirect stderr of your program in to gvim you can do:

myprogram 2>&1 | gvim -

and in case if you want to redirect the stdout to the editor you can do:

myprogram| gvim -
梦罢 2024-10-03 01:00:11

我在 Ubuntu 12.04 中尝试过此操作,它按预期工作:

sudo lshw | gedit &

在 Ubuntu 14.04

sudo lshw | gedit - &

Dimitry K 上于 16 年 1 月 22 日 19:00 添加了以下内容,

我认为您仍然需要破折号:(

gedit sudo lshw | gedit - & 

尝试了 ubuntu 14.04,只有破折号才有效) –

I tried this in Ubuntu 12.04, it works as desired:

sudo lshw | gedit &

On Ubuntu 14.04

sudo lshw | gedit - &

Dimitry K added on Jan 22 '16 at 19:00 the following

I think you still need dash after:

gedit sudo lshw | gedit - & 

(tried ubuntu 14.04 and only with dash it works) –

后来的我们 2024-10-03 01:00:11

要使用任何编辑器在一行中完成这一切,请创建一个临时文件,使用 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 -

另类 2024-10-03 01:00:11

我不知道有哪个编辑器支持此功能,但重定向到临时文件可能会更容易。

F=$(mktemp)
myprogram >$F
gedit $F
rm $F

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
喜爱皱眉﹌ 2024-10-03 01:00:11
history | kate -i

我最喜欢的编辑器:-)

正如已经说过的,当程序不支持此类管道时,最好的方法是使用目录 /tmp/ 中的临时文件,该文件通常会在下次启动时删除。

history > /tmp/bflmpsvz;mcedit /tmp/bflmpsvz
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.

history > /tmp/bflmpsvz;mcedit /tmp/bflmpsvz
榕城若虚 2024-10-03 01:00:11

vipe 这样做是为了任意 $EDITOR,可通过 brew install moreutils 在 macOS /homebrew 上使用

command1 |毒蛇 |命令2

vipe 允许您在 unix 管道中间运行编辑器并编辑在程序之间通过管道传输的数据。您的编辑器将从 command1 加载到其中的完整数据通过管道传输,当您关闭它时,该数据将通过管道传输到 command2

EDITOR:要使用的编辑器。

vipe does this for an arbitrary $EDITOR, available on macOS /homebrew via brew install moreutils

command1 | vipe | command2

vipe allows you to run your editor in the middle of a unix pipeline and edit the data that is being piped between programs. Your editor will have the full data being piped from command1 loaded into it, and when you close it, that data will be piped into command2.

EDITOR: Editor to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文