linux---保存标准输出和标准错误
linux---保存标准输出和标准错误
keywords: 重定向
示例程序:
#include <stdio.h>
int main() {
    // 写入标准输出 (stdout)
    printf("This is a message to stdout.\n");
    // 写入标准错误 (stderr)
    fprintf(stderr, "This is a message to stderr.\n");
    return 0;
}
// gcc -o test test.c
只保存到文件,分别保存:
./test > stdout.txt 2> stderr.txt
既输出到终端,也保存到文件,分别保存:
./test 2> >(tee stderr.txt >&2) | tee stdout.txt
既输出到终端,也保存到文件,保存在一个文件内:
./test 2>&1 | tee output_and_errors.txt
参考链接:
https://pwn.college/linux-luminarium/piping/
腾讯元宝
2024/10/17
    有些东西,分享就好
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号