Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"write error: stdout" when calling "make" from Makefile

This is my Makefile:

SHELL=/bin/bash
.SHELLFLAGS = -e -o pipefail -c 

env:
    make -version | head -1

This is what I’m getting on Ubuntu 20.04.3:

make -version | head -1
GNU Make 4.2.1
make[1]: write error: stdout
make: *** [Makefile:4: env] Error 1

What’s wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I don’t see this problem with GNU make 4.3, so I guess something was changed there to allow this to work.

To fix it you can try changing your rule to this:

env:
        make -version | cat | head -1

The error is because the head program closes its stdin when it’s read the first line, then make complains because it fails to write to its stdout (because it was closed).

By introducing the cat here, the cat reads all the input from make without closing the pipe so make doesn’t get any error.

PS. You should always, always use the variable $(MAKE) when invoking a sub-make, never the hardcoded make.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading