how to get the value from cmd prompt to c++?

Discussion in 'C++' started by IceCream, May 26, 2010.

  1. IceCream

    IceCream New Member

    Joined:
    May 26, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    using c++ with command prompt codes... i wanna know how to get the value from cmd prompt to c++?

    example i want to get the hostname:

    char x;
    x=system("FOR /F \"usebackq tokens=1\" %B IN (`hostname`) do echo %B"); :freak:

    something like this... :)
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Redirect the output to a file, then open the file after the system() command and read it.
    Alternatively find out how to do this by using OS calls - that's how the shell does it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice