sheredom / subprocess.h

🐜 single header process launching solution for C and C++
The Unlicense
1.12k stars 97 forks source link

Subprocess does not have internet access? #31

Closed jonatino closed 3 years ago

jonatino commented 3 years ago

I've got a really weird bug that I cant seem to figure out. I'm using your library to spawn a child java process for my game client.

The problem is when I start the client using subprocess.h, it does not have any internet access at all and throws a bunch of exceptions.

java.net.UnknownHostException: No such host is known (js5.pvpherodev.com)
        at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
        at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:932)
        at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1505)
        at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:851)
        at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1495)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1354)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1288)
        at java.base/java.net.InetAddress.getByName(InetAddress.java:1238)
        at pvphero/com.pvphero.client.Signlink.run(Signlink.java:165)
        at java.base/java.lang.Thread.run(Thread.java:832)

Here is the C++ code which spawns that process

void Updater::LaunchClient() {
    auto dev = true;

    struct subprocess_s process{};
    int result = -1;

    if (dev) {
        const char *command_line[] = {"java.exe", "-p",
                                      R"(E:\Sync\Insignia\hd-client\out\production\classes;E:\Sync\Insignia\hd-client\out\production\resources)",
                                      "-m", "pvphero/com.pvphero.PvpHero", /*"-hidden",*/ "-live", NULL};
        result = subprocess_create(command_line, subprocess_option_combined_stdout_stderr, &process);
    } else {
        const char *command_line[] = {getJavaPath().c_str(), "-m", "pvphero/com.pvphero.PvpHero",
                                      "-live", /*"-hidden",*/ NULL};
        result = subprocess_create(command_line, 0, &process);
    }

    if (0 != result) {
        std::cout << "Failed" << std::endl;
    }
}

If I run my client from command line with the exact same params as in the C++ code it works.

Screenshot of running the process spawned manually from command line (works with internet access): https://dl.dropboxusercontent.com/s/1566obcus51qxsy/ProcessHacker_iHNItCSlU1.png

Screenshot of the running process spawned via C++/subprocess.h (no internet access and fails to resolve domain): https://dl.dropboxusercontent.com/s/tazv5eaykbeomvj/ProcessHacker_8pD2audHMF.png

Any idea what could be causing this?

jonatino commented 3 years ago

Fixed this. Had to add the inherit environment option.

subprocess_create(command_line, subprocess_option_combined_stdout_stderr | subprocess_option_inherit_environment, &process);

I still think this is an issue just based off the description for the subprocess_option_inherit_environment option.

Feel free to close this if it's expected behavior.

sheredom commented 3 years ago

I'll add a comment describing this issue to the readme, just incase the next person finds the same issue!