I was trying to redirect the output from an arduino ( USB ) to some file at the computer using the next code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
int main()
{
pid_t pid;
pid = fork();
if (pid == 0) {
execl("/bin/cat","cat /dev/cu.usbmodem1421 - 9600 >> data.txt",NULL);
}
printf("Cuando desee terminar la recolección de datos presione cualquier tecla: ");
getchar();
kill(pid, SIGKILL);
return 0;
}
Using ps to verify if everything is fine, i can see the process running behind my main program. After stoping the program the data file has nothing on it. I tried to use system() which is a little bit nasty because i need to kill the program manually using OSX terminal. I think maybe the syntaxis is wrong and all i need is to add another parameter but nothing seems to work.