4

I can understand why writing to stdout and stderr would have output, but why stdin?

#include <unistd.h>

int
main()
{
  const char test[] = "test test test\n";
  write(STDIN_FILENO, test, sizeof(test) - 1);
  return 0;
}

EDIT: For those who want to give it a try, you can compile and run the program here

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
PuffySparrow
  • 897
  • 3
  • 10
  • 23
  • 1
    This has been answered in http://stackoverflow.com/questions/7383803/writing-to-stdin-and-reading-from-stdout-unix-linux-c-programming – CS Pei Jan 07 '16 at 01:43
  • Suppose that you `fork()` and have created a pipe between the child and the parent, then you can write to the parents `stdin` from the child, and to the childs `stdin` from the parent. So writing to `stdin` is not undefined for sure, as to why the shell outputs it, I have no clue. – Iharob Al Asimi Jan 07 '16 at 01:43

0 Answers0