Author Topic: Writing results in a file ?  (Read 3186 times)

YotaMtch

  • Guest
Writing results in a file ?
« on: September 26, 2008, 10:32:36 am »
Hi.
I wanted to know if there was a way to make (directly from Code::Blocks interface, i know how to do it in console) my program write its results in a file instead (or at the same time) of  a window. Setting the program's arguments doesn't seem to work.
Oh, and i don't want to use fstreams either (my students still don't know they even exist).

Thank you.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Writing results in a file ?
« Reply #1 on: September 26, 2008, 05:41:45 pm »
Directly, as supported by the interface, no.

However, if you have Gnuwin32 or something similar on your computer, you cand do one of two things:
1. replace console_runner with a batch file that runs the real console runner through tee
2. run your program as post-build step, again through tee.

You may want to file a feature request (and possibly a patch, it should not be too hard to implement) at BerliOS for this. If you implement a working patch, it will likely be implemented in trunk and nightly builds very soon. Not having looked at the actual code, I guess it won't be more than 10-15 lines of code for such a patch.

Under Project --> Set Program's arguments, there is a file selector field "host application". Code::Blocks uses the provided program name if your project builds a dynamic library, so the library can be "run" via the host application. Executable programs are normally standalone, so this doesn't make sense here. However, as you've presented in your case, it may still be useful.
It would only be logical to extend this functionality insofar as if a host application is given with a target that produces an executable, the respective program should be launched and the project target's output executable be given as last argument.
That would enable you to simply enter some program and some arguments and filter any of your programs through any other program.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."