2014-07-19 171 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