Originally Posted by
apawamajawa
I'm really new to the pipes. I would also appreciate it, if I could get a simple example code of just a few lines, which shows how to do this.
Alright, there are actually a few ways of doing this. I'll just give you some pseudo-code to get you started, since I don't actually have anything that does this lying around.
Code:
mkfifo(pipe_name, ...);
int id = fork();
if(id)
{
int fd = open(pipe_name, O_RDONLY);
close(STDIN);
dup2(fd, STDIN);
execv(...);
}
sleep(1); // wait for the sibling to open the FIFO
int fd = open(pipe_name, O_WRONLY);
write(fd, "Key press string here\n", ...); // this sends input to the sibling (which should now be your browser), and it doesn't know the difference
Of course, you'll need to do some error checking, fill in the blanks, etc.. But otherwise this should get you started.
Originally Posted by
apawamajawa
"then replace your program's stdin":
Should I use freopen here or something else?
I suppose you could. Though, I had a FIFO in mind. See my example above.