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
22 #include "ecore_private.h"
24 #define WIN32_LEAN_AND_MEAN
26 #undef WIN32_LEAN_AND_MEAN
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 */
46 HANDLE process_thread;
52 Ecore_Exe_Flags flags;
53 Ecore_Exe_Win32_Signal sig;
54 Ecore_Win32_Handler *h_close;
69 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_win32_pipe_thread_generic_cb(void *data, Ecore_Exe_Flags flags);
99 static DWORD WINAPI _ecore_exe_win32_pipe_thread_read_cb(void *data);
100 static DWORD WINAPI _ecore_exe_win32_pipe_thread_error_cb(void *data);
101 static int _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh);
102 static void _ecore_exe_pipe_read_cb(void *data, void *buf, unsigned int size);
103 static int _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh);
104 static void _ecore_exe_pipe_error_cb(void *data, void *buf, unsigned int size);
106 EAPI int ECORE_EXE_EVENT_ADD = 0;
107 EAPI int ECORE_EXE_EVENT_DEL = 0;
108 EAPI int ECORE_EXE_EVENT_DATA = 0;
109 EAPI int ECORE_EXE_EVENT_ERROR = 0;
112 _ecore_exe_init(void)
114 ECORE_EXE_EVENT_ADD = ecore_event_type_new();
115 ECORE_EXE_EVENT_DEL = ecore_event_type_new();
116 ECORE_EXE_EVENT_DATA = ecore_event_type_new();
117 ECORE_EXE_EVENT_ERROR = ecore_event_type_new();
121 _ecore_exe_shutdown(void)
124 ecore_exe_free(exes);
127 static int run_pri = NORMAL_PRIORITY_CLASS;
130 ecore_exe_run_priority_set(int pri)
134 case ECORE_EXE_WIN32_PRIORITY_IDLE:
135 run_pri = IDLE_PRIORITY_CLASS;
137 case ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL:
138 run_pri = BELOW_NORMAL_PRIORITY_CLASS;
140 case ECORE_EXE_WIN32_PRIORITY_NORMAL:
141 run_pri = NORMAL_PRIORITY_CLASS;
143 case ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL:
144 run_pri = ABOVE_NORMAL_PRIORITY_CLASS;
146 case ECORE_EXE_WIN32_PRIORITY_HIGH:
147 run_pri = HIGH_PRIORITY_CLASS;
149 case ECORE_EXE_WIN32_PRIORITY_REALTIME:
150 run_pri = REALTIME_PRIORITY_CLASS;
158 ecore_exe_run_priority_get(void)
162 case IDLE_PRIORITY_CLASS:
163 return ECORE_EXE_WIN32_PRIORITY_IDLE;
164 case BELOW_NORMAL_PRIORITY_CLASS:
165 return ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL;
166 case NORMAL_PRIORITY_CLASS:
167 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
168 case ABOVE_NORMAL_PRIORITY_CLASS:
169 return ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL;
170 case HIGH_PRIORITY_CLASS:
171 return ECORE_EXE_WIN32_PRIORITY_HIGH;
172 case REALTIME_PRIORITY_CLASS:
173 return ECORE_EXE_WIN32_PRIORITY_REALTIME;
174 /* default should not be reached */
176 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
181 ecore_exe_run(const char *exe_cmd, const void *data)
183 return ecore_exe_pipe_run(exe_cmd, 0, data);
187 ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
190 PROCESS_INFORMATION pi;
191 Ecore_Exe_Event_Add *e;
195 exe = calloc(1, sizeof(Ecore_Exe));
199 if ((flags & ECORE_EXE_PIPE_AUTO) && (!(flags & ECORE_EXE_PIPE_ERROR))
200 && (!(flags & ECORE_EXE_PIPE_READ)))
201 /* We need something to auto pipe. */
202 flags |= ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_ERROR;
205 if (exe->flags & ECORE_EXE_PIPE_READ)
206 if (!_ecore_exe_win32_pipes_set(exe))
209 if (exe->flags & ECORE_EXE_PIPE_WRITE)
210 if (!_ecore_exe_win32_pipes_set(exe))
213 if (exe->flags & ECORE_EXE_PIPE_ERROR)
214 if (!_ecore_exe_win32_pipes_set(exe))
217 if ((exe->flags & ECORE_EXE_USE_SH) ||
218 ((ret = strrstr(exe_cmd, ".bat")) && (ret[4] == '\0')))
221 snprintf(buf, PATH_MAX, "cmd.exe /c %s", exe_cmd);
222 exe->cmd = strdup(buf);
225 exe->cmd = strdup(exe_cmd);
230 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
232 ZeroMemory(&si, sizeof(STARTUPINFO));
233 si.cb = sizeof(STARTUPINFO);
234 si.hStdOutput = exe->pipe_read.child_pipe_x;
235 si.hStdInput = exe->pipe_write.child_pipe;
236 si.hStdError = exe->pipe_error.child_pipe_x;
237 si.dwFlags |= STARTF_USESTDHANDLES;
239 /* FIXME: gerer la priorite */
241 if (!CreateProcess(NULL, exe->cmd, NULL, NULL, EINA_TRUE,
242 run_pri | CREATE_SUSPENDED, NULL, NULL, &si, &pi))
245 /* be sure that the child process is running */
246 /* FIXME: This does not work if the child is an EFL-based app */
247 /* if (WaitForInputIdle(pi.hProcess, INFINITE) == WAIT_FAILED) */
248 /* goto free_exe_cmd; */
250 ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE);
251 exe->process = pi.hProcess;
252 exe->process_thread = pi.hThread;
253 exe->process_id = pi.dwProcessId;
254 exe->thread_id = pi.dwThreadId;
255 exe->data = (void *)data;
257 if (!(exe->process2 = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SUSPEND_RESUME | PROCESS_TERMINATE | SYNCHRONIZE,
258 EINA_FALSE, pi.dwProcessId)))
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 if (ResumeThread(exe->process_thread) == ((DWORD)-1))
267 exes = (Ecore_Exe *)eina_inlist_append(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
269 e = (Ecore_Exe_Event_Add *)calloc(1, sizeof(Ecore_Exe_Event_Add));
270 if (!e) goto delete_h_close;
273 ecore_event_add(ECORE_EXE_EVENT_ADD, e,
274 _ecore_exe_event_add_free, NULL);
279 ecore_main_win32_handler_del(exe->h_close);
281 CloseHandle(exe->process2);
283 CloseHandle(exe->process_thread);
284 CloseHandle(exe->process);
288 _ecore_exe_win32_pipes_close(exe);
295 ecore_exe_callback_pre_free_set(Ecore_Exe *exe, void (*func)(void *data, const Ecore_Exe *exe))
297 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
299 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
300 "ecore_exe_callback_pre_free_set");
303 exe->pre_free_cb = func;
307 ecore_exe_send(Ecore_Exe *exe, const void *data, int size)
311 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
313 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_send");
317 if (exe->close_stdin)
319 ERR("Ecore_Exe %p stdin is closed! Cannot send %d bytes from %p",
324 if (!exe->pipe_write.child_pipe)
326 ERR("Ecore_Exe %p created without ECORE_EXE_PIPE_WRITE! "
327 "Cannot send %d bytes from %p", exe, size, data);
331 buf = realloc(exe->pipe_write.data_buf, exe->pipe_write.data_size + size);
332 if (buf == NULL) return 0;
334 exe->pipe_write.data_buf = buf;
335 memcpy((char *)exe->pipe_write.data_buf + exe->pipe_write.data_size, data, size);
336 exe->pipe_write.data_size += size;
338 /* if (exe->pipe_write.) */
339 /* ecore_main_fd_handler_active_set(exe->pipe_write.h, ECORE_FD_WRITE); */
345 ecore_exe_close_stdin(Ecore_Exe *exe)
347 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
349 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_close_stdin");
352 exe->close_stdin = 1;
355 /* Not used on Windows */
357 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__)
361 EAPI Ecore_Exe_Event_Data *
362 ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags)
364 Ecore_Exe_Event_Data *e = NULL;
365 unsigned char *inbuf;
368 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
370 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_event_data_get");
374 /* Sort out what sort of event we are, */
375 /* And get the data. */
376 if (flags & ECORE_EXE_PIPE_READ)
378 inbuf = exe->pipe_read.data_buf;
379 inbuf_num = exe->pipe_read.data_size;
380 exe->pipe_read.data_buf = NULL;
381 exe->pipe_read.data_size = 0;
385 inbuf = exe->pipe_error.data_buf;
386 inbuf_num = exe->pipe_error.data_size;
387 exe->pipe_error.data_buf = NULL;
388 exe->pipe_error.data_size = 0;
391 e = calloc(1, sizeof(Ecore_Exe_Event_Data));
403 ecore_exe_event_data_free(Ecore_Exe_Event_Data *e)
412 ecore_exe_free(Ecore_Exe *exe)
416 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
418 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_free");
424 if (exe->pre_free_cb)
425 exe->pre_free_cb(data, exe);
427 CloseHandle(exe->process2);
428 CloseHandle(exe->process_thread);
429 CloseHandle(exe->process);
431 _ecore_exe_win32_pipes_close(exe);
432 exes = (Ecore_Exe *)eina_inlist_remove(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
433 ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
434 if (exe->tag) free(exe->tag);
441 ecore_exe_pid_get(const Ecore_Exe *exe)
443 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
445 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pid_get");
448 return exe->process_id;
452 ecore_exe_tag_set(Ecore_Exe *exe, const char *tag)
454 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
456 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_set");
461 exe->tag = strdup(tag);
465 ecore_exe_tag_get(const Ecore_Exe *exe)
467 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
469 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_get");
476 ecore_exe_cmd_get(const Ecore_Exe *exe)
478 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
480 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_cmd_get");
487 ecore_exe_data_get(const Ecore_Exe *exe)
489 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
491 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
498 ecore_exe_flags_get(const Ecore_Exe *exe)
500 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
502 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
509 ecore_exe_pause(Ecore_Exe *exe)
511 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
513 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pause");
517 if (exe->is_suspended)
520 if (SuspendThread(exe->process_thread) != (DWORD)-1)
521 exe->is_suspended = 1;
525 ecore_exe_continue(Ecore_Exe *exe)
527 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
529 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_continue");
533 if (!exe->is_suspended)
536 if (ResumeThread(exe->process_thread) != (DWORD)-1)
537 exe->is_suspended = 0;
541 ecore_exe_interrupt(Ecore_Exe *exe)
543 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
545 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_interrupt");
549 CloseHandle(exe->process_thread);
550 CloseHandle(exe->process);
551 exe->sig = ECORE_EXE_WIN32_SIGINT;
552 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
556 ecore_exe_quit(Ecore_Exe *exe)
558 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
560 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_quit");
564 CloseHandle(exe->process_thread);
565 CloseHandle(exe->process);
566 exe->sig = ECORE_EXE_WIN32_SIGQUIT;
567 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
571 ecore_exe_terminate(Ecore_Exe *exe)
573 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
575 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_terminate");
579 /* CloseHandle(exe->thread); */
580 CloseHandle(exe->process);
581 exe->sig = ECORE_EXE_WIN32_SIGTERM;
582 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
586 ecore_exe_kill(Ecore_Exe *exe)
588 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
590 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_kill");
594 CloseHandle(exe->process_thread);
595 CloseHandle(exe->process);
596 exe->sig = ECORE_EXE_WIN32_SIGKILL;
597 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
601 ecore_exe_signal(Ecore_Exe *exe, int num __UNUSED__)
603 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
605 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_signal");
613 ecore_exe_hup(Ecore_Exe *exe)
615 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
617 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_hup");
624 /* FIXME: manage error mode */
626 _ecore_exe_win32_pipe_thread_generic_cb(void *data, Ecore_Exe_Flags flags)
631 char *current_buf = NULL;
633 Ecore_Pipe *ecore_pipe;
634 Ecore_Exe_Event_Data *event;
636 DWORD current_size = 0;
639 exe = (Ecore_Exe *)data;
641 /* Sort out what sort of handler we are. */
642 /* And get any left over data from last time. */
643 if ((exe->flags & ECORE_EXE_PIPE_READ) && (flags == ECORE_EXE_PIPE_READ))
645 child_pipe = exe->pipe_read.child_pipe;
646 ecore_pipe = exe->pipe_read.p;
647 flags = ECORE_EXE_PIPE_READ;
649 else if ((exe->flags & ECORE_EXE_PIPE_ERROR) && (flags == ECORE_EXE_PIPE_ERROR))
651 child_pipe = exe->pipe_error.child_pipe;
652 ecore_pipe = exe->pipe_error.p;
653 flags = ECORE_EXE_PIPE_ERROR;
660 if (!PeekNamedPipe(child_pipe, buf, 1, &size, ¤t_size, NULL))
664 current_buf = (char *)malloc(current_size);
667 res = ReadFile(child_pipe, current_buf, current_size, &size, NULL);
668 if (!res || (size == 0))
674 if (current_size != size)
682 if (flags == ECORE_EXE_PIPE_READ)
684 exe->pipe_read.data_buf = current_buf;
685 exe->pipe_read.data_size = current_size;
689 exe->pipe_error.data_buf = current_buf;
690 exe->pipe_error.data_size = current_size;
693 event = ecore_exe_event_data_get(exe, flags);
695 ecore_pipe_write(ecore_pipe, &event, sizeof(event));
705 _ecore_exe_win32_pipe_thread_read_cb(void *data)
707 return _ecore_exe_win32_pipe_thread_generic_cb(data, ECORE_EXE_PIPE_READ);
711 _ecore_exe_win32_pipe_thread_error_cb(void *data)
713 return _ecore_exe_win32_pipe_thread_generic_cb(data, ECORE_EXE_PIPE_ERROR);
717 _ecore_exe_win32_pipes_set(Ecore_Exe *exe)
719 SECURITY_ATTRIBUTES sa;
723 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
724 sa.bInheritHandle = EINA_TRUE;
725 sa.lpSecurityDescriptor = NULL;
727 if (!CreatePipe(&child_pipe, &child_pipe_x, &sa, 0))
729 if (exe->flags & ECORE_EXE_PIPE_WRITE)
731 if (!SetHandleInformation(child_pipe_x, HANDLE_FLAG_INHERIT, 0))
736 if (!SetHandleInformation(child_pipe, HANDLE_FLAG_INHERIT, 0))
740 if (exe->flags & ECORE_EXE_PIPE_READ)
742 exe->pipe_read.child_pipe = child_pipe;
743 exe->pipe_read.child_pipe_x = child_pipe_x;
744 exe->pipe_read.p = ecore_pipe_add(_ecore_exe_pipe_read_cb, exe);
745 exe->pipe_read.thread = CreateThread(NULL, 0,
746 _ecore_exe_win32_pipe_thread_read_cb,
749 else if (exe->flags & ECORE_EXE_PIPE_WRITE)
751 exe->pipe_write.child_pipe = child_pipe;
752 exe->pipe_write.child_pipe_x = child_pipe_x;
753 /* exe->pipe_write.thread = CreateThread(NULL, 0, */
754 /* _ecore_exe_win32_pipe_thread_cb, */
759 exe->pipe_error.child_pipe = child_pipe;
760 exe->pipe_error.child_pipe_x = child_pipe_x;
761 exe->pipe_error.p = ecore_pipe_add(_ecore_exe_pipe_error_cb, exe);
762 exe->pipe_error.thread = CreateThread(NULL, 0,
763 _ecore_exe_win32_pipe_thread_error_cb,
770 CloseHandle(child_pipe);
771 CloseHandle(child_pipe_x);
777 _ecore_exe_win32_pipes_close(Ecore_Exe *exe)
779 if (exe->flags & ECORE_EXE_PIPE_READ)
781 if (exe->pipe_read.child_pipe)
783 CloseHandle(exe->pipe_read.child_pipe);
784 exe->pipe_read.child_pipe = NULL;
786 if (exe->pipe_read.child_pipe_x)
788 CloseHandle(exe->pipe_read.child_pipe_x);
789 exe->pipe_read.child_pipe_x = NULL;
793 if (exe->flags & ECORE_EXE_PIPE_WRITE)
795 if (exe->pipe_write.child_pipe)
797 CloseHandle(exe->pipe_write.child_pipe);
798 exe->pipe_write.child_pipe = NULL;
800 if (exe->pipe_write.child_pipe_x)
802 CloseHandle(exe->pipe_write.child_pipe_x);
803 exe->pipe_write.child_pipe_x = NULL;
807 if (exe->flags & ECORE_EXE_PIPE_ERROR)
809 if (exe->pipe_error.child_pipe)
811 CloseHandle(exe->pipe_error.child_pipe);
812 exe->pipe_error.child_pipe = NULL;
814 if (exe->pipe_error.child_pipe_x)
816 CloseHandle(exe->pipe_error.child_pipe_x);
817 exe->pipe_error.child_pipe_x = NULL;
823 _ecore_exe_thread_procedure(LPVOID data __UNUSED__)
825 GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
826 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0);
831 _ecore_exe_enum_windows_procedure(HWND window, LPARAM data)
836 exe = (Ecore_Exe *)data;
837 thread_id = GetWindowThreadProcessId(window, NULL);
839 if (thread_id == exe->thread_id)
841 /* Ctrl-C or Ctrl-Break */
842 if (CreateRemoteThread(exe->process, NULL, 0,
843 (LPTHREAD_START_ROUTINE)_ecore_exe_thread_procedure, NULL,
846 printf ("remote thread\n");
850 if ((exe->sig == ECORE_EXE_WIN32_SIGINT) ||
851 (exe->sig == ECORE_EXE_WIN32_SIGQUIT))
853 printf ("int or quit\n");
857 /* WM_CLOSE message */
858 PostMessage(window, WM_CLOSE, 0, 0);
859 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
865 /* WM_QUIT message */
866 PostMessage(window, WM_QUIT, 0, 0);
867 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
874 if (CreateRemoteThread(exe->process, NULL, 0,
875 (LPTHREAD_START_ROUTINE)ExitProcess, NULL,
878 printf ("remote thread 2\n");
882 if (exe->sig == ECORE_EXE_WIN32_SIGTERM)
888 TerminateProcess(exe->process, 0);
897 _ecore_exe_event_add_free(void *data __UNUSED__, void *ev)
899 Ecore_Exe_Event_Add *e;
901 e = (Ecore_Exe_Event_Add *)ev;
906 _ecore_exe_event_del_free(void *data __UNUSED__, void *ev)
908 Ecore_Exe_Event_Del *e;
910 e = (Ecore_Exe_Event_Del *)ev;
912 ecore_exe_free(e->exe);
917 _ecore_exe_event_exe_data_free(void *data __UNUSED__, void *ev)
919 Ecore_Exe_Event_Data *e;
921 e = (Ecore_Exe_Event_Data *)ev;
922 ecore_exe_event_data_free(e);
926 _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
928 Ecore_Exe_Event_Del *e;
932 e = calloc(1, sizeof(Ecore_Exe_Event_Del));
935 exe = (Ecore_Exe *)data;
937 if (GetExitCodeProcess(exe->process2, &exit_code))
939 e->exit_code = exit_code;
946 msg = evil_last_error_get();
950 e->pid = exe->process_id;
953 ecore_event_add(ECORE_EXE_EVENT_DEL, e,
954 _ecore_exe_event_del_free, NULL);
960 _ecore_exe_pipe_read_cb(void *data, void *buf, unsigned int size)
962 Ecore_Exe_Event_Data *e;
964 e = *((Ecore_Exe_Event_Data **)buf);
966 ecore_event_add(ECORE_EXE_EVENT_DATA, e,
967 _ecore_exe_event_exe_data_free,
972 _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
974 char buf[READBUFSIZ];
979 exe = (Ecore_Exe *)data;
981 res = WriteFile(exe->pipe_write.child_pipe_x, buf, READBUFSIZ, &num_exe, NULL);
982 if (!res || num_exe == 0)
984 /* FIXME: what to do here ?? */
987 if (exe->close_stdin == 1)
989 if (exe->pipe_write.h)
991 ecore_main_win32_handler_del(exe->pipe_write.h);
992 exe->pipe_write.h = NULL;
994 exe->pipe_write.h = NULL;
995 CloseHandle(exe->pipe_write.child_pipe);
996 exe->pipe_write.child_pipe = NULL;
1003 _ecore_exe_pipe_error_cb(void *data, void *buf, unsigned int size)
1005 Ecore_Exe_Event_Data *e;
1007 e = *((Ecore_Exe_Event_Data **)buf);
1009 ecore_event_add(ECORE_EXE_EVENT_ERROR, e,
1010 _ecore_exe_event_exe_data_free,