Shienar Shienar - 1 year ago 64
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download