0

Is it possible to fool a windows program (using a python script or any other shell to launch it) into believing that its output isn't redirected, so the output is not buffered ?

(Well, that's a simular question as forcing a program to flush its standard output when redirected except that it's windows specific, the question only tackles linux)

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • isatty() is a very low-level call. Patching the GetFileType winapi function with another program is only theoretically possible. – Hans Passant Sep 27 '17 at 10:25
  • @HansPassant, do you mean to hook `GetFileType` to check if it's querying a standard handle, and in that case always return `FILE_TYPE_CHAR`? – Eryk Sun Sep 27 '17 at 10:28
  • I think I found some `unbuffer` program equivalent for windows, I have to test it (needs MSYS2): https://stackoverflow.com/questions/11516258/what-is-the-equivalent-of-unbuffer-program-on-windows – Jean-François Fabre Sep 27 '17 at 12:24
  • @Jean-FrançoisFabre, that's interesting, but it's not actually fooling the program, unlike Linux stdbuf. It's really using a console. I've used console screen buffers with child processes before, but only in the simple case when I can use a large screen with 9,999 lines and not have to worry about scrolling. The screen buffer isn't like a pipe that blocks when full, so winpty has to poll it. I wonder how reliable that is. Other programs such as ConEmu use DLL injection to hook `WriteFile` and `WriteConsole` in the target process. – Eryk Sun Sep 27 '17 at 13:01
  • I'd suggest trying `com0com` or similar, should work without having to scrape screen buffers *or* injecting into the target process. I haven't actually tried it though. – Harry Johnston Sep 27 '17 at 23:21
  • Does this answer your question? [forcing a program to flush its standard output when redirected](https://stackoverflow.com/questions/2055918/forcing-a-program-to-flush-its-standard-output-when-redirected) – Umut TEKİN Aug 07 '22 at 10:05

0 Answers0