On Tuesday, August 5, 2014 6:51:06 AM UTC-3, Geert Jansen wrote: > > Hi, > > Windows has very little terminal emulation support but the basics of > starting a console program and redirecting it standard input / output are > there and possible without any DLL injection hacks. I've done it in a past > project of mine called winpexpect See the link here: > > https://bitbucket.org/geertj/winpexpect > > (there's also a repo on Github with the same name but that's an abandoned > WIP - don't use it) > > The builtin support won't allow you to build a decent terminal emulator > but it does allow you to automate most command-line programs including > cmd.exe and powershell. Out of curiosity what do you require in addition to > this? > > I would love to see PTY support in uv_process, but I think it will have to > be a Unix specific flag. > > Regards, > Geert >
The problem is that some programs behave differently when stdio is connected to a terminal(eg: python interpreter). As I said, it would be possible to implement a full terminal emulation library for windows, but it would be far from trivial. I can see two possible ways to attack the problem: - Inject code into the child process to poll for $CONOUT/$CONIN data in a separate thread and communicate with the emulator using a pipe. This is what Console2 does. - Take winpty approach which I haven't investigated, but I guess it involves starting a 'pty agent'(a proxy daemon that somehow manages to get the data from the console program) I'm not sure if libuv devs would accept adding a flag that only works on UNIX and is ignored on windows, but here's the code I have so far if you want to continue from where I stopped: https://gist.github.com/tarruda/08e3a5cb5ebade8acc97 It still needs some improvements: - An API function to resize the child process terminal(eg: uv_resize_terminal(uv_process_t *, int cols, int rows)) - Refactor to use `posix_openpt` which is seems to be standard posix way of opening pseudo-terminals. The `openpty` function is non-standard and requires an extra `-lutil` link. - Add more tests Note that my goal was to provide the simplest API that would behave similarly on windows or unixes, so it has these limitations: - All std file descriptors have to be redirected when using the UV_PROCESS_CREATE_TERMINAL flag - The UV_PROCESS_CREATE_TERMINAL flag also implies that the child process is started in a new session(so it receives signals independently from the parent) and has a controlling terminal. In windows terms it means the process owns the console. -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
