Thread: Getting Text from Console commands

  1. #1
    Unregistered
    Guest

    Getting Text from Console commands

    HI,

    Can any one tell me that how can i get results from sevral commands like dir , Time , Ping etc from my dialog based Application without showing their black console windows.

    Thanks!

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hey,

    I dunno if this is the best way, but it works. Call the dos command with system() or CreateProcess() or whatever you want to use, and send the command/results out to a temp file that your prog can delete when its finished:

    Code:
    system("dir >> c:\test.txt");
    You now have the info you need in c:\test.txt, however this does pop up the annoying console box, you would need to use a different function to do that.

    Now you would just need to read in test.txt into a varible, and then delete it with DeleteFile("c:\test.txt");

    I would tell you how to read in but i cant remember the code offhand, sorry but let me know if you need it


    Hope that helps,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    Unregistered
    Guest
    Thanks! TNT

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You can do as suggested above....but a more professional way to do it is to use the feature provided with CreateProcess...you can run the command without creating a consol...and also give custom handles for stdin & stdout - and then just read these handles and handle the IO yourself


    look here

  5. #5
    Unregistered
    Guest
    Ok! but Create Process is some what difficult to understand will you please tell me that how can i use this function

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console app: Making pretty text blocks
    By unit335 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2009, 07:22 PM
  2. Text Justification for console output
    By greywolf0723 in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2009, 12:29 AM
  3. Scrolling text in a DOS CONSOLE box
    By Blizzarddog in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2004, 02:27 PM
  4. How to print Right aligned Text in a console?
    By Aidman in forum C++ Programming
    Replies: 13
    Last Post: 03-09-2003, 10:43 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM