]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/console.cpp
Add functions to support console redirection
[libs/core.git] / source / io / console.cpp
index d06b894e10dda771f11773999b18e8ee92c2d204..259f80fbdf5ca21802099d9108c779f1bb9c0f53 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef WIN32
 #include <errno.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
 #include <sys/ioctl.h>
@@ -125,6 +126,16 @@ void Console::get_size(unsigned &rows, unsigned &cols)
 #endif
 }
 
+void Console::redirect(Base &other)
+{
+       Handle other_handle = other.get_handle(mode&M_RDWR);
+#ifdef WIN32
+       SetStdHandle(stream_to_sys(stream), *other_handle);
+#else
+       dup2(*other_handle, *handle);
+#endif
+}
+
 unsigned Console::do_write(const char *buf, unsigned len)
 {
        check_access(M_WRITE);