If it is a windows program then using <PrintScreen> or <Alt>-<PrintScreen> (to capture the focused window only) is your best bet.
If it is a console program and you are outputing using printf or a similar function then you have a couple of options.
Programatically you could add lines of code that close the current stdout and open a file in place of it.
A little more simply you can use the pipe capabilities of the command line. Assuming that you program is call test.exe and you want the results in results.txt then either
text.exe > results.txt
or
text.exe >> results.txt
The first line deletes the current contents of results.txt, the second method appends the output of the program to the current contents of results.txt.