21

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?

6 Answers 6

21

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 -
2
  • 2
    Yes, '-' stands in many programs for STDIN/STDOUT instead of a file.
    – eumiro
    Commented Oct 5, 2010 at 14:56
  • It's not even stderr that I want. Simply stdout. How is it possible I didn't though out to using file -! Answer is simply myprogram | gvim - . Commented Oct 5, 2010 at 14:59
12

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

2
  • Additional information: This is a new feature in Gedit. It was introduced in the version that came with Gnome 3.0. See bugzilla.gnome.org/show_bug.cgi?id=121891 .
    – Lii
    Commented Sep 25, 2013 at 14:27
  • 2
    I think you still need dash after gedit sudo lshw | gedit - & (tried ubuntu 14.04 and only with dash it works)
    – Dimitry K
    Commented Jan 22, 2016 at 19:00
6

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 -

2

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
2
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
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.