0

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.

DrBeco
  • 11,237
  • 9
  • 59
  • 76
  • You can safely forget about `makeprg`. It's broken by design, and it will never do whayt you want. You might stand more chances if you use `system()` and `cgetexpr` instead, provided that you read the sources and figure out the right incantations for `shell`, `shellcmdflag`, `shellpipe`, `shellquote`, `shellredir`, `shellslash`, `shelltemp`, `shellxquote`, and `shellxescape`. Yes, it's that bad. – lcd047 Jul 12 '15 at 19:15
  • Thank you. Your comment, although not solved the question, was a nice inspiration. I started to play with `makeprg=bash -c...`, just to realize, due to error messages, that `makeprg` was itself using `bash -c...`. So I simplified things (see answer bellow). – DrBeco Jul 12 '15 at 20:46

2 Answers2

1

A little bit late, but... You can use pipe, just add additional double backslash:

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ \\\|\ tee\ teeerrors.err
Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46
0

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

DrBeco
  • 11,237
  • 9
  • 59
  • 76