开发者

How to pipe program output in an editor?

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?


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 -


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) –


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.

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜