Search code examples
gccvimmakefiletee

How to makeprg gcc pipe tee errors.err in vim?


I want to pipe stderr from gcc to tee errors.err but I got no luck trying this two pieces I made up:

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>\ >(tee\ errors.err)

The file is there, but its blank. At first I thought :make was deleting it, but even using set makeef=makeerrors.err the errors.err file was still blank.

The other (and actually my previous) solution was:

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ |\ tee\ errors.err

But I got this error I never figured out how to eliminate: E10: \ should be followed by /, ? or &


Edit 1: I've tried to use other filename also, like teerrors.err, just in case. Same problem.

Edit 2: I also tried:

set shellredir=2>errorsredir.err
!gcc % -o %<.x

to no avail. But, anyway, this wouldn't be a solution, because I cant set makeprg to a filter.

Edit 3: This one (extra \ in the pipe)

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ \|\ tee\ teeerrors.err

Gives vim error: E492: Not an editor command: tee teeerrors.err

I just run out of ideas.


Solution

  • I think I found a solution. Simpler than I thought.

    :set makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>errors.err;\ cat\ errors.err
    

    Bottom line: you can't pipe. (At least I couldn't find a solution with pipes).