How to redirect STDIN of CMD.exe in C++ programme
Hi All
I am trying to redirect STD handles of cmd.exe in my programmes. I am able to redierct STDOUT and STDERR, but rediercting STDIN is not workin. I wiash that whenevr i create a new process "CMD.exe" it should obtain its input from a file say input is 'dir' and write the output to a file.
I am able to write the output to a file , but I am unable to redirect the STDIN of the process. I have tried using CreatePipe , but eve that is not helpin. Any live CODE example on how to do it will be very helpful.
Thanks in advance..
Sumit Chawla

How to redirect STDIN of CMD.exe in C++ programme?
Next
One from Microsoft (linked to by the other links):
http://support.microsoft.com/kb/q190351/
and two from CodeProject:
http://www.codeproject.com/threads/redir.asp
http://www.codeproject.com/threads/consolepipe.asp
Alternately, to launch arbitrary remote command-line processes, you can use the PsExec program found in SysInternal's PsTools package and redirect PsExec's input/output and let it worry about the remote process management:
http://www.sysinternals.com/Utilities/PsTools.html
-Extrarius
solidtransient
There is a full sample in the MSDN, did you make it in this way
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp
Craig Harrison
whitesky
Hi
Thanks for the suggestion. But that does not suit me need. Because that way the CMD.exe cant be made to behave in an intercative way. Infact i want o invoke this functionnality on a remote computer. If i use batch file than it would not work for interactive commands like 'More' and dir /p...
Can you suggest any other way of acheving this functionality..
Thanks ...
D. Schwabe
Thanks for the answer. yes I have chacked this article. In this Article the Child.exe uses the Readfile function to read from the Pipe. But in my case the Process is CMD.exe. According to standard definition , i create a pipe , and assocated the Read Handle of this pipe to Startup_Info structure while creating the CMD.exe process.
Then process starts and waits for the Input from Pipe. then i wrote the "dir" command to the other end of pipe using WriteFile function. But the "Cmd.exe" does not read it from the pipe. I have mayself tried to use the ReadFile function to chack if data is getting there to the other end of pipe, and was able to successfully read from the pipe. But the process CMD.exe does not behave the same.
Kindly guide, or point to some code example where STDIN of CMD.exe have been redirected to a file or Pipe.
I also tried to redirect STDIN of CMD.exe to a HANDLE to an inuput file, but no gain.ON the other hand , I am able to successfully redierct the STDOUT and STDERR of CMD.exe using HANDLES to files.
Thanks