[Named Pipe] Redirection of STDIN and STDOUT
Hello,
Before I make this code and after some searching, I wanted to know if it is possible to redirect STDOUT and SDTIN to "Named Pipes" which was created by another process.
The goal is to quickly change the code of a console application that interacts with the user. Check it to launch if the "named piped exists, if so, it redefines the standard flow, otherwise we keep the default ones.
Apparently, I would have to turn to the dup () but I am pissed off is that it takes an integer parameter and CreateNamedPipe () returns a handle ... So I think that this will not work, I am wrong?
Is this possible and if this is true, how do I do to achieve it "simply" because I want to avoid setting a mechanism for ReadFile () and WriteFile (), unless I have the choice ...
NB: The choice of "pipe" is a design choice because I also used when creating another process using CreateProcess ().
Re: [Named Pipe] Redirection of STDIN and STDOUT
Quote:
I wanted to know if it is possible to redirect STDOUT and STDIN to "Named Pipes" which was created by another process.
If your named pipes exist, why use CreateNamedPipe ()?
As for your function dup (), I do not know what it is.
However, if you wish to obtain a handle to your pipe, you have to CreateFile (), as often elsewhere. You can also use CallNamedPipe () that combines several functions, including the previous one, to establish an easy interaction with your named pipes.
Finally, with regard to the redirection, you must turn to SetStdHandle () which handles the input and output (STD_OUTPUT_HANDLE. ..) are substituted by those tubes.
That is quite a summary of the thing that will allow you to move forward.
Re: [Named Pipe] Redirection of STDIN and STDOUT
Quote:
If your named pipes exist, why use CreateNamedPipe ()?
I'm can not be expressed, I said that another process has created the previously named pipes.
Quote:
Finally, with regard to the redirection, you must turn to SetStdHandle () which handles the input and output (STD_OUTPUT_HANDLE. ..) are substituted by those tubes.
Ah, here is what I missed.
I use the IDE Code: Blocks and MinGW as compiler.
Thank you!