Created
October 29, 2009 23:42
-
-
Save jcromartie/221943 to your computer and use it in GitHub Desktop.
How to tell if your command line tool is being piped-to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
if (!isatty(1)) { | |
printf("thanks for piping me, dude\n"); | |
} else { | |
printf("oh good, I'm not piped\n"); | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment