Reputation: 3774
I want to know if it is posible in linux and C to find out that my programs output is redirected to a file.
I want to format the output human readable when it is printed on stdout $ ./myprogram
and like csv when it is redirected to a file $ ./myprogram >> data.csv
is it posible?
Upvotes: 5
Views: 130
Reputation: 409206
You can use the isatty
function for that:
if (isatty(STDOUT_FILENO))
{
/* Standard out is an interactive terminal */
}
else
{
/* Standard out is something else (pipe, file redirect, etc.) */
}
Upvotes: 10