boostorg / process

Boost Process
https://www.boost.org/libs/process
118 stars 116 forks source link

Feature request: Add support for pty fds in process #399

Open leha-bot opened 2 months ago

leha-bot commented 2 months ago

The main use case is for batch run some apps which doesn't understand "non-tty" stdin.

Windows supports this from win10 , 1803 and requires the special HANDLEs created via CreatePseudoConsole Linux creates these pty via openpty(3).

klemens-morgenstern commented 1 month ago

What do you have in mind here? An IO Object for the ability to set this for a subprocess?

leha-bot commented 1 month ago

I thought about some kind of API like (it's not exactly boost process API, just bikeshedding in bp v1 API style):

bp::pty pty;
bp::process child("/some/binary", bp::std_in > pty, bp::std_out < pty);

std::string process_output_line;
pty >> process_output_line; // read string from process (until first space , or use std::getline())
pty << 15; // write to child' stdin via pty

Currently, there is no portable way (at least I tried to (ab)use the posix file descriptors, but no luck, pipe helpers won't work with same pty fd and either copies them, or hangs)

klemens-morgenstern commented 2 weeks ago

I did some work here: https://github.com/boostorg/process/tree/pty

I don't think I'll finish it, the windows API is just too hostile and the posix one is straight forward enough to not need built-in support.