Click here to Skip to main content
15,888,202 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to run few commands that needs wmic but don't want to use system because of two reasons
1)it open command prompt which i don't want to show to the user
2)it uses .txt file to write result into which is then get later fro this file

but i want to use pipes if possible so that i can get the following things without system()function in c++ and can directly store the result in variables without the need of opening files writing results into it and then get it from these files
1)Ipv4 Address
2)UUid

What I have tried:

	system("ipconfig > ip.txt");
system("wmic csproduct get uuid > Uuid.txt")
Posted
Updated 11-Feb-20 2:45am

You can also directly access WMI from C++ (through COM), see WMI C++ Application Examples - Win32 apps | Microsoft Docs[^].
 
Share this answer
 
If you want to capture the output from executing a program, use _popen(). eg
C
#include <iostream>
#include <cstdio>

int main()
{
    FILE *pipe = _popen("ipconfig", "r");
    
    if(pipe == NULL) {
        perror("popen");
        return 1;
    }

    char buffer[256];

    while(fgets(buffer, sizeof buffer, pipe) != NULL) {
        std::cout << buffer;
    }

    _pclose(pipe);

    return 0;
}
 
Share this answer
 
Comments
Member 12899279 12-Feb-20 0:44am    
thanks K5054 actually i did exactly the same thing you have posted but my issue is still there that it still shos console window for a split second and i don't want to show th console at all

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900