-1

I have the following steps in a Docker build stage:

make shared > clbuild.log
export CRYPTLIB_BUILD_EXIT_CODE=$?
if [ ${CRYPTLIB_BUILD_EXIT_CODE} -ge 0 ]; then exit 1 ;fi

The warnings will still go to output with:

make shared > clbuild.log

How might i get make to log everything to 'clbuild.log' file, and not show any output at all, warnings or errors?

I wish to rather simply rely on exit code to indicate success or fail. (And abort and display the log only upon failure to build)

DhP
  • 306
  • 1
  • 11

1 Answers1

1

Programs always output to two streams, stdout and stderr, with IDs 1 and 2 respectively. You must tell you shell to dump stderr into stdout, with > ... 2>&1, or less verbosely, &>.

Anyway I think trying to mess with the build process is a loss of time

n.caillou
  • 1,263
  • 11
  • 15
  • Thanks for quick response. So '$> clbuild.log' instead of simply '> clbuild.log' would input it **all** to the same log file? – DhP Feb 02 '19 at 19:07
  • With '''make shared 2>&1 > clbuild.log''' it still outputs warns, though not in red text. – DhP Feb 02 '19 at 19:13
  • 1
    @DhP Please look at the [dupe](https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash). – G.M. Feb 02 '19 at 19:18
  • Note: `make shared >> clbuild.log 2>&1 ` (the portable solution from the the dupe, solved my problem. – DhP Feb 02 '19 at 19:54
  • Just a note: this will _append_ so if the file already exists you'll add your content to the end. If you want to _replace_ the content so if the output file already exists it will be truncated and your content written at the beginning, use `>clbuild.log 2>&1` instead. Note further that `&>` is a non-standard feature available in bash, while make always invokes `/bin/sh` by default. On some systems `/bin/sh` is actually bash and this will work; on other systems `/bin/sh` is a POSIX standard shell and it will fail. Best to stay with standard behavior. – MadScientist Feb 03 '19 at 13:37