以下の内容はhttps://ryuichi1208.hateblo.jp/entry/2021/06/20/210804より取得しました。


【Linux】io.h: No such file or directory

謎な技術だったので調べた。結論としてはisattyのようなライブラリ関数を使うかfstatでstdoutのステータスを判定すれば良さそう

#include <stdio.h>

int main(int argc, char **argv)
{
    if (isatty(fileno(stdout)))
        printf( "stdin is a terminal\n" );
    else
        printf( "stdin is a file or a pipe\n");
}

みたいに書いておけばstdoutの後続にパイプがあれば出力を抑制なり整形するみたいな処理を書くことができる。

fstatならマクロを使う。

struct stat stats;
fstat(0, &stats);
if (S_ISCHR(stats.st_mode)) {
    // Looks like a tty, so we're in interactive mode.
} else if (S_ISFIFO(stats.st_mode)) {
    // Looks like a pipe, so we're in non-interactive mode.
}



以上の内容はhttps://ryuichi1208.hateblo.jp/entry/2021/06/20/210804より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14