grep complains because it has more output than 10 lines, and head disables it until completion.
I suggest hiding the grep stderr output (the broken pipe error is printed here).
system("grep 1 tmp.txt 2>/dev/null | head -n 10")
This will not work if you need to see other errors from grep; in this case, you will need a more complex solution.
source share