Thread: C program to invoke commands and retrieve responses from windows command prompt

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    C program to invoke commands and retrieve responses from windows command prompt

    Hey guys,

    I'm trying to create a program that will run commands like ping, ipconfig, etc. in the windows command prompt as well as retrieve (and parse) the responses from those commands. Was wondering if someone could point me in the right direction on how to do this, or any useful site links on this

    Thank you kindly,
    smidge

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Look into popen/pclose in stdio.h.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I suppose the first question to pop into my head is ... Why not just use the command prompt?

    However; you should know there are windows API calls for almost all of that stuff and you don't need to shell out and do convoluted data gathering to use them...

    For example...
    If you are using ping to get a remote machine's IP address (a common abuse of the program) you can just call gethostbyname() from the Winsock API....

    If you are looking to use ipconfig to harvest local IPs, you can simply call, yep, gethostbyname() using the result of GetComputerName() to retrive IPs for your local system.

    Yes, what you want to do is possible but it is s...l...o...w and very error prone.

Popular pages Recent additions subscribe to a feed