2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 * - manage I/O pipes (several ones, and stdin)
8 * - manage SetConsoleCtrlHandler ?
9 * - the child process seems to still run after the DEL event
17 #define WIN32_LEAN_AND_MEAN
19 #undef WIN32_LEAN_AND_MEAN
27 #include "ecore_private.h"
29 #define ECORE_EXE_WIN32_TIMEOUT 3000
33 ECORE_EXE_WIN32_SIGINT,
34 ECORE_EXE_WIN32_SIGQUIT,
35 ECORE_EXE_WIN32_SIGTERM,
36 ECORE_EXE_WIN32_SIGKILL
37 } Ecore_Exe_Win32_Signal;
45 HANDLE process; /* CloseHandle */
52 Ecore_Exe_Flags flags;
53 Ecore_Exe_Win32_Signal sig;
54 Ecore_Win32_Handler *h_close;
60 Ecore_Win32_Handler *h;
70 Ecore_Win32_Handler *h;
77 Ecore_Win32_Handler *h;
82 Eina_Bool close_stdin : 1;
83 Eina_Bool is_suspended : 1;
85 void (*pre_free_cb)(void *data, const Ecore_Exe *exe);
88 static Ecore_Exe *exes = NULL;
90 static int _ecore_exe_win32_pipes_set(Ecore_Exe *exe);
91 static void _ecore_exe_win32_pipes_close(Ecore_Exe *exe);
93 static BOOL CALLBACK _ecore_exe_enum_windows_procedure(HWND window, LPARAM data);
94 static void _ecore_exe_event_add_free(void *data, void *ev);
95 static void _ecore_exe_event_del_free(void *data, void *ev);
96 static void _ecore_exe_event_exe_data_free(void *data,
98 static int _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh);
99 static int _ecore_exe_pipe_read_cb(void *data, Ecore_Win32_Handler *wh);
100 static int _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh);
101 static int _ecore_exe_pipe_error_cb(void *data, Ecore_Win32_Handler *wh);
103 EAPI int ECORE_EXE_EVENT_ADD = 0;
104 EAPI int ECORE_EXE_EVENT_DEL = 0;
105 EAPI int ECORE_EXE_EVENT_DATA = 0;
106 EAPI int ECORE_EXE_EVENT_ERROR = 0;
109 _ecore_exe_init(void)
111 ECORE_EXE_EVENT_ADD = ecore_event_type_new();
112 ECORE_EXE_EVENT_DEL = ecore_event_type_new();
113 ECORE_EXE_EVENT_DATA = ecore_event_type_new();
114 ECORE_EXE_EVENT_ERROR = ecore_event_type_new();
118 _ecore_exe_shutdown(void)
121 ecore_exe_free(exes);
124 static int run_pri = NORMAL_PRIORITY_CLASS;
127 ecore_exe_run_priority_set(int pri)
131 case ECORE_EXE_WIN32_PRIORITY_IDLE:
132 run_pri = IDLE_PRIORITY_CLASS;
134 case ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL:
135 run_pri = BELOW_NORMAL_PRIORITY_CLASS;
137 case ECORE_EXE_WIN32_PRIORITY_NORMAL:
138 run_pri = NORMAL_PRIORITY_CLASS;
140 case ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL:
141 run_pri = ABOVE_NORMAL_PRIORITY_CLASS;
143 case ECORE_EXE_WIN32_PRIORITY_HIGH:
144 run_pri = HIGH_PRIORITY_CLASS;
146 case ECORE_EXE_WIN32_PRIORITY_REALTIME:
147 run_pri = REALTIME_PRIORITY_CLASS;
155 ecore_exe_run_priority_get(void)
159 case IDLE_PRIORITY_CLASS:
160 return ECORE_EXE_WIN32_PRIORITY_IDLE;
161 case BELOW_NORMAL_PRIORITY_CLASS:
162 return ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL;
163 case NORMAL_PRIORITY_CLASS:
164 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
165 case ABOVE_NORMAL_PRIORITY_CLASS:
166 return ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL;
167 case HIGH_PRIORITY_CLASS:
168 return ECORE_EXE_WIN32_PRIORITY_HIGH;
169 case REALTIME_PRIORITY_CLASS:
170 return ECORE_EXE_WIN32_PRIORITY_REALTIME;
171 /* default should not be reached */
173 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
178 ecore_exe_run(const char *exe_cmd, const void *data)
180 return ecore_exe_pipe_run(exe_cmd, 0, data);
184 ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
187 PROCESS_INFORMATION pi;
188 Ecore_Exe_Event_Add *e;
192 exe = calloc(1, sizeof(Ecore_Exe));
196 if ((flags & ECORE_EXE_PIPE_AUTO) && (!(flags & ECORE_EXE_PIPE_ERROR))
197 && (!(flags & ECORE_EXE_PIPE_READ)))
198 /* We need something to auto pipe. */
199 flags |= ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_ERROR;
202 if (exe->flags & ECORE_EXE_PIPE_READ)
203 if (!_ecore_exe_win32_pipes_set(exe))
206 if (exe->flags & ECORE_EXE_PIPE_WRITE)
207 if (!_ecore_exe_win32_pipes_set(exe))
210 if (exe->flags & ECORE_EXE_PIPE_ERROR)
211 if (!_ecore_exe_win32_pipes_set(exe))
214 if ((exe->flags & ECORE_EXE_USE_SH) ||
215 ((ret = strrstr(exe_cmd, ".bat")) && (ret[4] == '\0')))
218 snprintf(buf, PATH_MAX, "cmd.exe /c %s", exe_cmd);
219 exe->cmd = strdup(buf);
222 exe->cmd = strdup(exe_cmd);
227 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
229 ZeroMemory(&si, sizeof(STARTUPINFO));
230 si.cb = sizeof(STARTUPINFO);
231 si.hStdOutput = exe->pipe_read.child_pipe_x;
232 si.hStdInput = exe->pipe_write.child_pipe;
233 si.hStdError = exe->pipe_error.child_pipe_x;
234 si.dwFlags |= STARTF_USESTDHANDLES;
236 /* FIXME: gerer la priorite */
238 if (!CreateProcess(NULL, exe->cmd, NULL, NULL, EINA_TRUE,
239 run_pri | CREATE_SUSPENDED, NULL, NULL, &si, &pi))
242 /* be sure that the child process is running */
243 /* FIXME: This does not work if the child is an EFL-based app */
244 /* if (WaitForInputIdle(pi.hProcess, INFINITE) != 0) */
245 /* goto free_exe_cmd; */
247 ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE);
248 exe->process = pi.hProcess;
249 exe->thread = pi.hThread;
250 exe->process_id = pi.dwProcessId;
251 exe->thread_id = pi.dwThreadId;
252 exe->data = (void *)data;
254 if (!(exe->process2 = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SUSPEND_RESUME | PROCESS_TERMINATE | SYNCHRONIZE,
255 EINA_FALSE, pi.dwProcessId)))
258 if (ResumeThread(exe->thread) == ((DWORD)-1))
261 exe->h_close = ecore_main_win32_handler_add(exe->process2, _ecore_exe_close_cb, exe);
262 if (!exe->h_close) goto close_process2;
264 exes = (Ecore_Exe *)eina_inlist_append(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
266 e = (Ecore_Exe_Event_Add *)calloc(1, sizeof(Ecore_Exe_Event_Add));
267 if (!e) goto delete_h_close;
270 ecore_event_add(ECORE_EXE_EVENT_ADD, e,
271 _ecore_exe_event_add_free, NULL);
276 ecore_main_win32_handler_del(exe->h_close);
278 CloseHandle(exe->process2);
280 CloseHandle(exe->thread);
281 CloseHandle(exe->process);
285 _ecore_exe_win32_pipes_close(exe);
292 ecore_exe_callback_pre_free_set(Ecore_Exe *exe, void (*func)(void *data, const Ecore_Exe *exe))
294 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
296 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
297 "ecore_exe_callback_pre_free_set");
300 exe->pre_free_cb = func;
304 ecore_exe_send(Ecore_Exe *exe, const void *data, int size)
309 ecore_exe_close_stdin(Ecore_Exe *exe)
311 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
313 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_close_stdin");
316 exe->close_stdin = 1;
319 /* Not used on Windows */
321 ecore_exe_auto_limits_set(Ecore_Exe *exe __UNUSED__, int start_bytes __UNUSED__, int end_bytes __UNUSED__, int start_lines __UNUSED__, int end_lines __UNUSED__)
325 EAPI Ecore_Exe_Event_Data *
326 ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags)
328 Ecore_Exe_Event_Data *e = NULL;
329 unsigned char *inbuf;
332 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
334 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_event_data_get");
338 /* Sort out what sort of event we are, */
339 /* And get the data. */
340 if (flags & ECORE_EXE_PIPE_READ)
342 inbuf = exe->pipe_read.data_buf;
343 inbuf_num = exe->pipe_read.data_size;
344 exe->pipe_read.data_buf = NULL;
345 exe->pipe_read.data_size = 0;
349 inbuf = exe->pipe_error.data_buf;
350 inbuf_num = exe->pipe_error.data_size;
351 exe->pipe_error.data_buf = NULL;
352 exe->pipe_error.data_size = 0;
355 e = calloc(1, sizeof(Ecore_Exe_Event_Data));
367 ecore_exe_event_data_free(Ecore_Exe_Event_Data *e)
376 ecore_exe_free(Ecore_Exe *exe)
380 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
382 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_free");
388 if (exe->pre_free_cb)
389 exe->pre_free_cb(data, exe);
391 ecore_main_win32_handler_del(exe->h_close);
392 CloseHandle(exe->process2);
393 CloseHandle(exe->thread);
394 CloseHandle(exe->process);
396 _ecore_exe_win32_pipes_close(exe);
397 exes = (Ecore_Exe *)eina_inlist_remove(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
398 ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
399 if (exe->tag) free(exe->tag);
406 ecore_exe_pid_get(const Ecore_Exe *exe)
408 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
410 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pid_get");
413 return exe->process_id;
417 ecore_exe_tag_set(Ecore_Exe *exe, const char *tag)
419 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
421 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_set");
426 exe->tag = strdup(tag);
430 ecore_exe_tag_get(const Ecore_Exe *exe)
432 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
434 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_get");
441 ecore_exe_cmd_get(const Ecore_Exe *exe)
443 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
445 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_cmd_get");
452 ecore_exe_data_get(const Ecore_Exe *exe)
454 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
456 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
463 ecore_exe_flags_get(const Ecore_Exe *exe)
465 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
467 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
474 ecore_exe_pause(Ecore_Exe *exe)
476 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
478 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pause");
482 if (exe->is_suspended)
485 if (SuspendThread(exe->thread) != (DWORD)-1)
486 exe->is_suspended = 1;
490 ecore_exe_continue(Ecore_Exe *exe)
492 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
494 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_continue");
498 if (!exe->is_suspended)
501 if (ResumeThread(exe->thread) != (DWORD)-1)
502 exe->is_suspended = 0;
506 ecore_exe_interrupt(Ecore_Exe *exe)
508 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
510 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_interrupt");
514 CloseHandle(exe->thread);
515 CloseHandle(exe->process);
516 exe->sig = ECORE_EXE_WIN32_SIGINT;
517 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
521 ecore_exe_quit(Ecore_Exe *exe)
523 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
525 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_quit");
529 CloseHandle(exe->thread);
530 CloseHandle(exe->process);
531 exe->sig = ECORE_EXE_WIN32_SIGQUIT;
532 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
536 ecore_exe_terminate(Ecore_Exe *exe)
538 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
540 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_terminate");
544 /* CloseHandle(exe->thread); */
545 CloseHandle(exe->process);
546 exe->sig = ECORE_EXE_WIN32_SIGTERM;
547 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
551 ecore_exe_kill(Ecore_Exe *exe)
553 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
555 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_kill");
559 CloseHandle(exe->thread);
560 CloseHandle(exe->process);
561 exe->sig = ECORE_EXE_WIN32_SIGKILL;
562 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
566 ecore_exe_signal(Ecore_Exe *exe, int num __UNUSED__)
568 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
570 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_signal");
578 ecore_exe_hup(Ecore_Exe *exe)
580 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
582 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_hup");
589 /* FIXME: manage error mode */
590 DWORD WINAPI _ecore_exe_win32_pipe_thread_cb(void *data)
595 char *current_buf = NULL;
598 DWORD current_size = 0;
600 exe = (Ecore_Exe *)data;
602 /* Sort out what sort of handler we are. */
603 /* And get any left over data from last time. */
604 if (exe->flags & ECORE_EXE_PIPE_READ)
606 child_pipe = exe->pipe_read.child_pipe;
610 child_pipe = exe->pipe_error.child_pipe;
617 res = ReadFile(child_pipe, buf, sizeof(buf), &size, NULL);
620 exe->pipe_read.pending = -123;
623 current_size += size;
624 current_buf = (char *)malloc(current_size);
625 memcpy(current_buf, buf, current_size);
629 current_buf = realloc(current_buf, current_size + size);
630 memcpy(current_buf + current_size, buf, size);
631 current_size += size;
638 res = GetLastError();
639 if (res == ERROR_IO_PENDING)
641 exe->pipe_read.pending = res;
644 if (res == ERROR_BROKEN_PIPE)
646 exe->pipe_read.pending = res;
649 if (res == ERROR_MORE_DATA)
651 exe->pipe_error.pending = -456;
657 if (exe->flags & ECORE_EXE_PIPE_READ)
659 if (exe->pipe_read.data_buf) free(exe->pipe_read.data_buf);
660 exe->pipe_read.data_size = 0;
661 exe->pipe_read.data_buf = malloc(current_size);
662 if (exe->pipe_read.data_buf)
664 memcpy(exe->pipe_read.data_buf, current_buf, current_size);
665 exe->pipe_read.data_size = current_size;
670 if (exe->pipe_error.data_buf) free(exe->pipe_error.data_buf);
671 exe->pipe_error.data_size = 0;
672 exe->pipe_error.data_buf = malloc(current_size);
673 if (exe->pipe_error.data_buf)
675 memcpy(exe->pipe_error.data_buf, current_buf, current_size);
676 exe->pipe_error.data_size = current_size;
684 _ecore_exe_win32_pipes_set(Ecore_Exe *exe)
686 SECURITY_ATTRIBUTES sa;
690 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
691 sa.bInheritHandle = EINA_TRUE;
692 sa.lpSecurityDescriptor = NULL;
694 if (!CreatePipe(&child_pipe, &child_pipe_x, &sa, 0))
696 if (exe->flags & ECORE_EXE_PIPE_WRITE)
698 if (!SetHandleInformation(child_pipe_x, HANDLE_FLAG_INHERIT, 0))
703 if (!SetHandleInformation(child_pipe, HANDLE_FLAG_INHERIT, 0))
707 if (exe->flags & ECORE_EXE_PIPE_READ)
709 exe->pipe_read.child_pipe = child_pipe;
710 exe->pipe_read.child_pipe_x = child_pipe_x;
711 exe->pipe_read.thread = CreateThread(NULL, 0,
712 _ecore_exe_win32_pipe_thread_cb,
714 exe->pipe_read.h = ecore_main_win32_handler_add(exe->pipe_read.thread, _ecore_exe_pipe_read_cb, exe);
716 else if (exe->flags & ECORE_EXE_PIPE_WRITE)
718 exe->pipe_write.child_pipe = child_pipe;
719 exe->pipe_write.child_pipe_x = child_pipe_x;
720 /* exe->pipe_write.thread = CreateThread(NULL, 0, */
721 /* _ecore_exe_win32_pipe_thread_cb, */
726 exe->pipe_error.child_pipe = child_pipe;
727 exe->pipe_error.child_pipe_x = child_pipe_x;
728 exe->pipe_error.thread = CreateThread(NULL, 0,
729 _ecore_exe_win32_pipe_thread_cb,
731 exe->pipe_error.h = ecore_main_win32_handler_add(exe->pipe_error.thread, _ecore_exe_pipe_error_cb, exe);
737 CloseHandle(child_pipe);
738 CloseHandle(child_pipe_x);
744 _ecore_exe_win32_pipes_close(Ecore_Exe *exe)
746 if (exe->flags & ECORE_EXE_PIPE_READ)
748 if (exe->pipe_read.child_pipe)
750 CloseHandle(exe->pipe_read.child_pipe);
751 exe->pipe_read.child_pipe = NULL;
753 if (exe->pipe_read.child_pipe_x)
755 CloseHandle(exe->pipe_read.child_pipe_x);
756 exe->pipe_read.child_pipe_x = NULL;
760 if (exe->flags & ECORE_EXE_PIPE_WRITE)
762 if (exe->pipe_write.child_pipe)
764 CloseHandle(exe->pipe_write.child_pipe);
765 exe->pipe_write.child_pipe = NULL;
767 if (exe->pipe_write.child_pipe_x)
769 CloseHandle(exe->pipe_write.child_pipe_x);
770 exe->pipe_write.child_pipe_x = NULL;
774 if (exe->flags & ECORE_EXE_PIPE_ERROR)
776 if (exe->pipe_error.child_pipe)
778 CloseHandle(exe->pipe_error.child_pipe);
779 exe->pipe_error.child_pipe = NULL;
781 if (exe->pipe_error.child_pipe_x)
783 CloseHandle(exe->pipe_error.child_pipe_x);
784 exe->pipe_error.child_pipe_x = NULL;
790 _ecore_exe_thread_procedure(LPVOID data __UNUSED__)
792 GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
793 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0);
798 _ecore_exe_enum_windows_procedure(HWND window, LPARAM data)
803 exe = (Ecore_Exe *)data;
804 thread_id = GetWindowThreadProcessId(window, NULL);
806 if (thread_id == exe->thread_id)
808 /* Ctrl-C or Ctrl-Break */
809 if (CreateRemoteThread(exe->process, NULL, 0,
810 (LPTHREAD_START_ROUTINE)_ecore_exe_thread_procedure, NULL,
813 printf ("remote thread\n");
817 if ((exe->sig == ECORE_EXE_WIN32_SIGINT) ||
818 (exe->sig == ECORE_EXE_WIN32_SIGQUIT))
820 printf ("int or quit\n");
824 /* WM_CLOSE message */
825 PostMessage(window, WM_CLOSE, 0, 0);
826 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
832 /* WM_QUIT message */
833 PostMessage(window, WM_QUIT, 0, 0);
834 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
841 if (CreateRemoteThread(exe->process, NULL, 0,
842 (LPTHREAD_START_ROUTINE)ExitProcess, NULL,
845 printf ("remote thread 2\n");
849 if (exe->sig == ECORE_EXE_WIN32_SIGTERM)
855 TerminateProcess(exe->process, 0);
864 _ecore_exe_event_add_free(void *data __UNUSED__, void *ev)
866 Ecore_Exe_Event_Add *e;
868 e = (Ecore_Exe_Event_Add *)ev;
873 _ecore_exe_event_del_free(void *data __UNUSED__, void *ev)
875 Ecore_Exe_Event_Del *e;
877 e = (Ecore_Exe_Event_Del *)ev;
879 ecore_exe_free(e->exe);
884 _ecore_exe_event_exe_data_free(void *data __UNUSED__, void *ev)
886 Ecore_Exe_Event_Data *e;
888 e = (Ecore_Exe_Event_Data *)ev;
889 ecore_exe_event_data_free(e);
893 _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
895 Ecore_Exe_Event_Del *e;
899 e = calloc(1, sizeof(Ecore_Exe_Event_Del));
902 exe = (Ecore_Exe *)data;
904 if (GetExitCodeProcess(exe->process2, &exit_code))
906 e->exit_code = exit_code;
913 msg = evil_last_error_get();
917 e->pid = exe->process_id;
920 _ecore_event_add(ECORE_EXE_EVENT_DEL, e,
921 _ecore_exe_event_del_free, NULL);
927 _ecore_exe_generic_cb(void *data, Ecore_Win32_Handler *wh)
930 Ecore_Exe_Event_Data *e;
931 Ecore_Win32_Handler *h;
934 Ecore_Exe_Flags flags;
939 exe = (Ecore_Exe *)data;
941 printf ("%s : **%d** **%d**\n", __FUNCTION__, exe->pipe_read.pending, exe->pipe_error.pending);
943 /* Sort out what sort of handler we are. */
944 /* And get any left over data from last time. */
945 if (exe->flags & ECORE_EXE_PIPE_READ)
947 flags = ECORE_EXE_PIPE_READ;
948 event_type = ECORE_EXE_EVENT_DATA;
949 thread = exe->pipe_read.thread;
950 h = exe->pipe_read.h;
954 flags = ECORE_EXE_PIPE_ERROR;
955 event_type = ECORE_EXE_EVENT_ERROR;
956 thread = exe->pipe_error.thread;
957 h = exe->pipe_error.h;
960 e = ecore_exe_event_data_get(exe, flags);
962 ecore_event_add(event_type, e,
963 _ecore_exe_event_exe_data_free,
968 if (exe->pipe_read.h)
969 ecore_main_win32_handler_del(h);
970 thread = CreateThread(NULL, 0,
971 _ecore_exe_win32_pipe_thread_cb,
973 if (exe->flags & ECORE_EXE_PIPE_READ)
975 exe->pipe_read.thread = thread;
979 exe->pipe_error.thread = thread;
981 /* exe->pipe_read.h = ecore_main_win32_handler_add(exe->pipe_read.thread, _ecore_exe_pipe_read_cb, exe); */
987 _ecore_exe_pipe_read_cb(void *data, Ecore_Win32_Handler *wh)
989 return _ecore_exe_generic_cb(data, wh);
993 _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
995 char buf[READBUFSIZ];
1000 exe = (Ecore_Exe *)data;
1002 res = WriteFile(exe->pipe_write.child_pipe_x, buf, READBUFSIZ, &num_exe, NULL);
1003 if (!res || num_exe == 0)
1005 /* FIXME: what to do here ?? */
1008 if (exe->close_stdin == 1)
1010 if (exe->pipe_write.h)
1011 ecore_main_win32_handler_del(exe->pipe_write.h);
1012 exe->pipe_write.h = NULL;
1013 CloseHandle(exe->pipe_write.child_pipe);
1014 exe->pipe_write.child_pipe = NULL;
1021 _ecore_exe_pipe_error_cb(void *data, Ecore_Win32_Handler *wh)
1023 return _ecore_exe_generic_cb(data, wh);