Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Saving console output to .txt/.html file using C++/VC++

Saving console output to .txt/.html file using C++/VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++htmltestingbeta-testing
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pk jain
    wrote on last edited by
    #1

    Hi, I am using CPPUNIT code for Unit testing purpose. I have created a Win32-console application to show its output. Now i want to generated TEXT/HTML/ formated file which will contain the excat lines{output} as in console o\p window. Please suggest what should be VC++ code to achive this requirement. Thanks

    L P 2 Replies Last reply
    0
    • P pk jain

      Hi, I am using CPPUNIT code for Unit testing purpose. I have created a Win32-console application to show its output. Now i want to generated TEXT/HTML/ formated file which will contain the excat lines{output} as in console o\p window. Please suggest what should be VC++ code to achive this requirement. Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You just need to use one of the file writing functions or fstream interfaces to write to a file. Check the documentation on MSDN.

      Use the best guess

      1 Reply Last reply
      0
      • P pk jain

        Hi, I am using CPPUNIT code for Unit testing purpose. I have created a Win32-console application to show its output. Now i want to generated TEXT/HTML/ formated file which will contain the excat lines{output} as in console o\p window. Please suggest what should be VC++ code to achive this requirement. Thanks

        P Offline
        P Offline
        pasztorpisti
        wrote on last edited by
        #3

        You can solve this in two different ways: Inside your program or outside your program. The "outside" solution is probably simpler and more roboust and easier to implement. Outside: When you are running your program you redirect its output to another program that does the following: prints the incoming data to the console but at the same time it writes it into a text file and of course at the same time it can do other things too with the log data. You can do the redirection either by writing another program that runs the test with redirected input/output or you can choose an easier solution, piping together programs with the help of your cmd or bash: Example python script that prints the input to console and logs to file at the same time: file: x.py

        import sys
        with open('logfile.txt', 'w') as log_file:
        while 1:
        s = sys.stdin.readline()
        if not s:
        break
        sys.stdout.write(s)
        log_file.write(s)
        log_file.flush()

        Commandline usage:

        TestProgram | python x.py

        Of course this program could be anything, not only a python script but a perl script or a c/C++ program or a java program. Inside: If you want to solve the problem inside your test program then create your own logger and log through that instead of using printf() or similar methods. In your logger you can create many outputs so when your test program logs something your logger can direct it towards different outputs for example a console writer output, a html writer output and a text file writer output. Almost forgot to mention: If you are on linux or you have cygwin on windows then you can use the tee command that does basically the same as the above python script.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups