How to save console output to text file?

we are working in codeblocks.we have created a console input output application.we have connected mysql as the database.now we want that whatever we query the result of the query should be stored in a text file.please guide.

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    bns
    we are working in codeblocks.we have created a console input output application.we have connected mysql as the database.now we want that whatever we query the result of the query should be stored in a text file.please guide.
    I'll assume you're on Windows operating system and console is your DOS prompt. In this situation, you will have to use the redirect operator.

    Let's say you want to capture the output of a 'DIR' command to a text file, you will have to issue the following command -

    C:\>DIR >log.txt
    This will store the output of DIR command to log.txt. However, if you execute the above command multiple times, the command will delete the previous contents. If you want to 'log' all the outputs one after the other, you will have to use the >> operator.

    C:\>DIR >>log.txt
    Now this will keep on adding the output of DIR command to log.txt one after the other in the form of a log file.

    I'm not sure if the following would work, but you may try giving it a try -

     C:\> CONSOLE >>log.txt 
    This should log everything on the console to a text file.

    Someone more familiar with DOS can help. Let us know if that helps.
  • bns
    bns
    where do we have to run this command?in codeblocks this command generated lot of errors
  • Kaustubh Katdare
    Kaustubh Katdare
    bns
    where do we have to run this command?in codeblocks this command generated lot of errors
    You run these commands in your DOS console. I'm not sure what you're trying to do. You will have to explain your problem a bit in more detail so that there's no room for assumption.

    We can't know which console you're referring to, which operating system you are using and what kind of errors you are getting.
  • bns
    bns
    we are using windows os and console is the screen where we get output after running any standard c++ program using codeblocks.

    now we have connected mysql to codeblocks and succesfully running the queries to get the result on console.what we want is to save the displayed result of queries in a text file just like we do in file handling.
  • rahul69
    rahul69
    #-Link-Snipped-# I guess u are talking about mysql console, 👀, if thats the case, u can simple use the select statement with into outfile option to get it to write to the text file.
    For example your query is:
    select * from testTable;
    to write result in file, u will have to write as :
    select * into outfile 'output.txt' from testTable; 
    It should solve your problem👍😀
  • Vishal Sharma
    Vishal Sharma
    I think you want it to be done automatically, so add a statement in your program
    cmd.setCommandText(_TSA("the query given by rahul69"));
    cmd.Execute();

    NOTE: this is using SQLAPI.h
  • bns
    bns
    thanks for the help. can u tell us how to convert mysql database into .xml file?
  • Vishal Sharma
    Vishal Sharma
    bns
    thanks for the help. can u tell us how to convert mysql database into .xml file?
    database into xml?? can you be a li'l clear?
  • bns
    bns
    Vishal0203
    database into xml?? can you be a li'l clear?
    sir,we want our relational database table which is in mysql to be converted into xml file.
  • Vishal Sharma
    Vishal Sharma
    bns
    sir,we want our relational database table which is in mysql to be converted into xml file.
    i don't know the exact way but, I can tell you a technique which you may find helpful.
    If you store your table in a .doc or .docx file, just go to the file location, right click, change the file extension from .doc or . docx to .rar

    When you are done, open the .rar file with Winrar or some other supporting software
    you'll have a number of .xml files inside the .rar file, which stores all the formatting of table and the contents.. (extension can be changed through program too)

    I'm not sure whether this will be helpful or not, still give a try!

You are reading an archived discussion.

Related Posts

Probably the most significant news so far from Microsoft this year is this - an update to the operating system they built keeping in mind the mobility-driven significant change in...
Engineers at NHK are developing an 8K Ultra HD television and the broadcasts are expected to begin in Japan in 2016. The camera head required is being jointly developed with...
Flipkart seems to be doing a ton of things to bring in revenues. The company recently shut down Flyte digital music store. In addition, now the company is said to...
The immensely successful, Steve-Jobs inspired Apple product 'the iPhone' is making it big in India. Thanks to the EMI as well as cash back schemes offered, Apple India's monthly iPhone...
Lenovo's Ultrabook Convertible, aptly christened IdeaPad Yoga 13, has been rolled out in India recently for over Rs 1,03,775/- with all its aluminium unibody awesomeness. With Windows 8 Pro OS...