gpt4 book ai didi

c - 发现我的程序的输出被重定向到一个文件中

转载 作者:IT王子 更新时间:2023-10-29 01:10:11 26 4
gpt4 key购买 nike

我想知道在 linux 和 C 中是否可以发现我的程序输出被重定向到一个文件。我想在 stdout $ ./myprogram 上打印输出时将其格式化为人类可读的格式,并在将其重定向到文件 $ ./myprogram >> data.csv 时设置为 csv >

这可能吗?

最佳答案

您可以使用 isatty功能:

if (isatty(STDOUT_FILENO))
{
/* Standard out is an interactive terminal */
}
else
{
/* Standard out is something else (pipe, file redirect, etc.) */
}

关于c - 发现我的程序的输出被重定向到一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com