2 Compile with gcc -o ecore_exe_example ecore_exe_example.c `pkg-config --cflags --libs ecore`
9 #define BUFFER_SIZE 1024
12 _msg_from_child_handler(void *data, int type, void *event)
14 Ecore_Exe_Event_Data *dataFromProcess = (Ecore_Exe_Event_Data *)event;
15 char msg[BUFFER_SIZE];
17 if (dataFromProcess->size >= (BUFFER_SIZE - 1))
19 fprintf(stdout, "Data too big for bugger. error\n");
20 return ECORE_CALLBACK_DONE;
23 strncpy(msg, dataFromProcess->data, dataFromProcess->size);
24 msg[dataFromProcess->size] = 0;
26 if (strcmp(msg, "quit") == 0)
28 fprintf(stdout, "My child said to me, QUIT!\n");
29 ecore_main_loop_quit();
32 fprintf(stdout, "I received a message from my child: %s\n", msg);
34 return ECORE_CALLBACK_DONE;
38 _sendMessage(void *data)
40 static int numberOfMessages = 0;
41 Ecore_Exe *childHandle = (Ecore_Exe *)data;
42 char msg[BUFFER_SIZE];
44 sprintf(msg, " Message: %d\n", numberOfMessages);
47 if (ecore_exe_send(childHandle, msg, strlen(msg)) != EINA_TRUE)
48 fprintf(stderr, "Could not send my name to the child\n");
51 "I'm the father and I sent this message to the child: %s\n", msg);
53 return ECORE_CALLBACK_RENEW;
57 main(int argc, char **argv)
60 Ecore_Exe *childHandle;
65 childHandle = ecore_exe_pipe_run("./ecore_exe_example_child",
66 ECORE_EXE_PIPE_WRITE |
67 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
68 ECORE_EXE_PIPE_READ, NULL);
70 if (childHandle == NULL)
72 fprintf(stderr, "Could not create a child process!\n");
76 childPid = ecore_exe_pid_get(childHandle);
79 fprintf(stderr, "Could not retrive the PID!\n");
81 fprintf(stdout, "The child process has PID:%d\n", childPid);
83 ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _msg_from_child_handler, NULL);
84 ecore_timer_add(1, _sendMessage, childHandle);
86 ecore_main_loop_begin();
88 ecore_exe_free(childHandle); //This will not affect the child process