I want to use fork() to spawn off a new process in my program. The new process will have only one task: To redirect the mouse input to a serial port. I have tested the follo
You cannot perform redirection in this way.
If you want to redirect stdout
for a process you're about to exec
, you need to open
the path and dup2
it onto the appropriate file descriptor.
Example:
if (!(pid = fork())
{
int fd = open("/dev/ttyS0", O_WRONLY);
dup2(fd, 1); // redirect stdout
execl("/usr/bin/hexdump", "hexdump", "/dev/input/mice", NULL);
}