title: Redirecting input from file to exec()
body: <p>I am making simple ANSI C program, that simulates Unix shell. So I am creating child process using fork() and inside child process I am calling exec() to run given (by user) program. </p>
  
  <p>What I need to do is redirect content of file to stdin, so it can be sent to user called program. </p>
  
  <p><code>Example: cat &lt; file \\user wants run cat and redirect content of that file to it by typing this to my program prompt</code></p>
  
  <p>I am trying to do so like this:</p>
  
  <pre><code>...child process...
  
  int fd = open(path_to_file, O_RDONLY);
  
  int read_size = 0;
  while ((read_size = read(fd, buffer, BUF_SIZE)) != 0) {
      write(STDIN_FILENO, buffer, read_size);
  }
  close(fd);
  
  execlp("cat", ...);
  </code></pre>
  
  <p>Everything goes fine, content of file is written to stdin, but after reading whole file, cat still waiting for an input (I need to tell cat, that input ended), but I cannot figure how :-(?</p>
  
  <p>Any ideas? Thanks a lot!!!</p>