sheredom / subprocess.h

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

Permanently redirect stdout on child process #30

Closed jonatino closed 3 years ago

jonatino commented 3 years ago

I have the following go code that I'm converting to c++

        javaPath := getJavaPath()

    cmd := exec.Command(javaPath, "-m", "pvphero/com.pvphero.PvpHero", "-live", "-hidden")

    if dev {
        cmd = exec.Command(javaPath, "-p", "E:\\Sync\\Insignia\\hd-client\\out\\production\\classes;E:\\Sync\\Insignia\\hd-client\\out\\production\\resources", "-m", "pvphero/com.pvphero.PvpHero", "-hidden", "-live")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
    }

    fmt.Println("Launching client", cmd)

    _ = cmd.Start()

I was wondering is there any way to redirect the stdout of my child process to share the same one as its parent process? Or will I just need to make another thread that loops/polls for stdout messages? I tried looking through the tests you have on here but couldn't find any similar use case.

PS. Your library is awesome.

sheredom commented 3 years ago

There is no way in the current API to do that. I guess an option could be added to https://github.com/sheredom/subprocess.h/blob/master/subprocess.h#L58 to facilitate it, but for now you'd have to do what you say.

sheredom commented 3 years ago

I've looked into this - its not something that is easy to do (especially on Windows).