📄 dup.c
字号:
/* dup.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
void DisplayOutput()
{
fprintf(stdout, "This is to stdout\n");
fprintf(stderr, "This is to stderr\n");
}
int main(int argc, char **argv)
{
int _newStdOut, _newStdErr;
//call the output routine
DisplayOutput();
//change the stdout and stderr file descriptors
_newStdOut = open("out", O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
_newStdErr = open("err", O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
dup2(_newStdOut, 1);
dup2(_newStdErr, 2);
//call the output routine again
DisplayOutput();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -