2014-07-19 173 views
0

我在做一个使用SDL库的项目。在Unix上重定向标准输出

我注意到stdout和stderr被重定向到2个文件:stdout.txt和stderr.txt。

我设法流重定向回Windows平台上,但我不能为Unix平台上做到这一点...

void redirectSDLStreams() { 
    #ifdef _WIN32 
    freopen("CONOUT$", "w", stdout); 
    freopen("CONOUT$", "w", stderr); 
    #elifdef __unix__ // Not sure about it tho 
    // Code for Unix 
    #endif 
} 

我想:

printf("Ok from stdout\n") // Prints something 
freopen("/dev/tty", "w", stdout); 
printf("Ok from /dev/tty\n") // Prints nothing 

和:

printf("Ok from stdout\n") // Prints something 
freopen("/dev/stdout", "w", stdout); 
printf("Ok from /dev/stdout\n") // Prints nothing 

但都未能在Fedora 17 ...

任何想法?

谢谢!

回答

0

freopen("/dev/tty", "w", stdout);没问题。但是,SDL从未在Linux上重新打开stdout/stderr。

SDL 1.2在windows上做了这些,并根据配置在mac os上做了这些。 SDL2放弃了这一点,现在从不重定向输出。

+0

很高兴知道,谢谢! – user3821901