Shienar Shienar - 6 months ago 31
Linux Question

How can make my makefile overwrite a file?

descript: progam.cpp
g++ progam.cpp -o descript
./descript 2>output.txt | tee -a output.txt

From my understanding, first command compiles program.cpp and the second command sends the output to both terminal and a textfile.

Is there a way to adjust this so that I :

  • Use "make".Go through program prompts. Output is saved in output.txt

  • Use "./descript" or some command a second time and overwrite output.txt with new output

I'm fairly new to linux commands in general so anything would help.


It may be helpful to include a make clean function in your Makefile.

Example make clean function could include:

make clean:
    rm -f output.txt

Then, insert the make clean at the beginning of your descript portion of the Makefile to auto-remove the previous output.