Reputation: 5
I was using the original makefile to build my code with Perl scripts written in makefile.
Now I want to print all the log shown on screen to a txt file.
What command can I use in my makefile in order to do this?
I was meant to use some command in makefile to output what will be shown on screen to a txt file. for example, if the makefile looks like:
all:
perl filename.pl
how should I write in my makefile so that every time I type"make all" in command line, it will automatically save the output to a txt file?
Hi now I need to improve it, I need to save the output to a txt file whose directory should according to the input of my perl script.
For example, in the makefile:
all:
$(X)make -C .. DIR=$(DIR) Y=$(Y) Z=$(Z)
perl filename.pl $(DIR)/$(Y)/i.lst 2>&1 | tee log.txt
how should I change in the makefile so that the log.txt will be saved at the directory equals the input $DIR? Ans I also want to change the name "log" to the input, how could I do this?
Can anyone help?
Upvotes: 0
Views: 9363
Reputation: 126185
You can have a make rule that invokes make recursively, redirecting things to a file:
all:
$(MAKE) everything >log.txt
everything: ...whatever you had before for all
Of course, if you just have one command, you might as well put the redirection in there:
all:
perl filename.pl >log.txt
If you want the output to both appear on the screen and be copied to the file, you can use tee
:
all:
perl filename.pl | tee log.txt
..and if you want to include stderr output in the file, you can redirect that too:
all:
perl filename.pl 2>&1 | tee log.txt
Upvotes: 4
Reputation: 13034
From the command line, piping the output from make to a text file should be pretty straightforward:
make > new_file.txt
Use two arrows instead if you want it to concatenate instead of replace each time:
make >> new_file.txt
Upvotes: 1