CrazyEngineers
  • How to save console output to text file?

    bns

    Member

    Updated: Oct 27, 2024
    Views: 1.1K
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorMay 30, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • bns

    MemberMay 30, 2013

    where do we have to run this command?in codeblocks this command generated lot of errors
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorMay 30, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • bns

    MemberMay 31, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberMay 31, 2013

    #-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👍😀
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberMay 31, 2013

    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
    Are you sure? This action cannot be undone.
    Cancel
  • bns

    MemberJun 5, 2013

    thanks for the help. can u tell us how to convert mysql database into .xml file?
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberJun 6, 2013

    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?
    Are you sure? This action cannot be undone.
    Cancel
  • bns

    MemberJun 6, 2013

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberJun 7, 2013

    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!
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register