tags:

views:

54

answers:

0

Hi, I have a small problem that I don't know how to solve.

I have a program which is basically commanded by inputs in stdin. It just keeps running until receives a particular string and then do something else. Ok, I don't have access to the code that controls these inputs but I would like to add a new command.

The idea I have is the following:

. Create a pipe in my program

. Fork the process

. One of them goes on with the the original program while the other reads from stdin.

. Redirect stdin of process that continued the usual execution to the pipe.

. The part that keeps listening from stdin, checks what is receives, if it is not the new command, just redirect the pipe (so that the old commands still work)

. If it is the new command, send a particular signal.

I've been thinking about implementing that with pipe/fork/dup2 in c++, but I don't know how I would send and catch a signal in the process that continued the execution. How can I do that in c++? Do you guys have any suggestion? Does this might work?