Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created October 29, 2009 23:42
Show Gist options
  • Save jcromartie/221943 to your computer and use it in GitHub Desktop.
Save jcromartie/221943 to your computer and use it in GitHub Desktop.
How to tell if your command line tool is being piped-to
#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