output -stats to file.txt

I’m estimating the number of basic blocks of the a program using “opt -stats bitecode.bc”
I would like to save the output of the -stats opt into a file .txt.
How can I do this?

Have you tried “opt -stats bitecode.bc > test.txt”?

Yes, I’ve tried and it did not work

Add an optimization level and you get information.

D:\ >opt -stats temp.bc -o tmp.bc2

D:\ >opt -stats temp.bc -o tmp.bc2 -O3

I already did. What I need is to have this output in a txt file.

Ahh, my bad, its outputting to stderr, not stdout, use ‘2> file.txt’.