Here is a link with an example program about redirection:
http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx[
^]
Of course you have to modify that according to your needs, you need to redirect only stdin. Note that a mistake that is easy to make is not marking the pipe handle as inheritable, and not closing the pipe handle on the parent side after the child process inherited it. In addition to this you have to decide whether to make this prog safe. If you go the easy way than you use just 1 thread, create the process, write its stdin (this may block), and then wait for the process to terminate. In this case your program may freeze (for example if the child process does not consume all your std input). Another solution is to use 2 threads. 1 thread can be busy by writing the stdin, the other thread can wait for the process to terminate. This way you can put in additional wait timeout to make your prog safe (
WaitForSingleObject()
on the process handle). If the process waiter thread returns from wait then it can terminate the other thread as well if that is still hanging on the write handle of the redirected stdin.