Another possibility is that foo uses isatty and doesn't write anything to stdout if stdout does not point somewhere interactive.
SYNOPSIS
#include <unistd.h>
int isatty(int fd);
DESCRIPTION
The isatty() function tests whether fd is an open file descriptor referring to a terminal.
This short Python program demonstrates it:
import sys, os
if sys.stdout.isatty():
print "Hello, tty %s" % os.ttyname(1)
else:
print "stdout: not a typewriter: how boring"
As does this short C program:
#include <stdio.h>
#include <unistd.h>
int main (void) {
if ( isatty(stdout) ) {
printf("Hello, tty %s\n", ttyname(1));
} else {
printf("stdout: not a typewriter: how boring\n");
}
return 0;
}
Both programs have the identical behaviour:
$ ./isatty > notatty ; cat notatty
stdout: not a typewriter: how boring
$ ./isatty.py
Hello, tty /dev/pts/1
$ ./isatty | cat
stdout: not a typewriter: how boring
Programs can choose how, what and whether or not they print based on whether they are being redirected.
A common application of this is to avoid writing ANSI escape sequences read by terminals (\e[33;1m, etc) for text colouring to files, which looks ugly and confuses parsers.