Forcing an action

closed account (38qG1hU5)
Could someone explain or link me something that would explain how to make another program open, do something, then close.

Example ----
This program opens cmd, types "ipconfig", hits enter, then copies "IP v4 address" (Please keep in mind I don't actually want to do this just an example.), Saves it. then closes itself.
closed account (28poGNh0)
Forcing an action
!

you can get those
opens cmd, types "ipconfig", hits enter
done easily with :

1
2
3
4
5
6
7
8
9
10
# include <iostream>
# include <cstdlib>
using namespace std;

int main()
{
    system("ipconfig");

    return 0;
}


copies "IP v4 address"


you should learn some sockets (I'll try to look up for one of my old codes (Dont count on me)).
closed account (38qG1hU5)
@techno01
thanks really helps, but I am looking for something to open and copy specific data. Sorry if this is confusing I'm quite new to this. I guess you could call what I want, a virus. Just to be clear this is not for malicious purposes. Just to explore the science.
Why don't use good old ipconfig | findstr IPv4 in command line? If you still want to do it in C++, you can use following to get output from executed command.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <stdio.h>

std::string exec(const char* cmd) {
    FILE* pipe = _popen(cmd, "r");
    if (!pipe) return "ERROR";
    char buffer[128];
    std::string result = "";
    while (!feof(pipe)) {
        if (fgets(buffer, 128, pipe) != NULL)
            result += buffer;
    }
    _pclose(pipe);
    return result;
}

int main()
{
    std::cout << exec("ipconfig | findstr IPv4");
}

Topic archived. No new replies allowed.