3 * - manage I/O pipes (several ones, and stdin)
4 * - manage SetConsoleCtrlHandler ?
5 * - the child process seems to still run after the DEL event
18 #include "ecore_private.h"
20 #define WIN32_LEAN_AND_MEAN
22 #undef WIN32_LEAN_AND_MEAN
25 #define ECORE_EXE_WIN32_TIMEOUT 3000
29 ECORE_EXE_WIN32_SIGINT,
30 ECORE_EXE_WIN32_SIGQUIT,
31 ECORE_EXE_WIN32_SIGTERM,
32 ECORE_EXE_WIN32_SIGKILL
33 } Ecore_Exe_Win32_Signal;
41 HANDLE process; /* CloseHandle */
42 HANDLE process_thread;
48 Ecore_Exe_Flags flags;
49 Ecore_Exe_Win32_Signal sig;
50 Ecore_Win32_Handler *h_close;
65 Ecore_Win32_Handler *h;
78 Eina_Bool close_stdin : 1;
79 Eina_Bool is_suspended : 1;
81 Ecore_Exe_Cb pre_free_cb;
84 static Ecore_Exe *exes = NULL;
86 static int _ecore_exe_win32_pipes_set(Ecore_Exe *exe);
87 static void _ecore_exe_win32_pipes_close(Ecore_Exe *exe);
89 static BOOL CALLBACK _ecore_exe_enum_windows_procedure(HWND window, LPARAM data);
90 static void _ecore_exe_event_add_free(void *data, void *ev);
91 static void _ecore_exe_event_del_free(void *data, void *ev);
92 static void _ecore_exe_event_exe_data_free(void *data,
94 static int _ecore_exe_win32_pipe_thread_generic_cb(void *data, Ecore_Exe_Flags flags);
95 static DWORD WINAPI _ecore_exe_win32_pipe_thread_read_cb(void *data);
96 static DWORD WINAPI _ecore_exe_win32_pipe_thread_error_cb(void *data);
97 static Eina_Bool _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh);
98 static void _ecore_exe_pipe_read_cb(void *data, void *buf, unsigned int size);
99 static int _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh);
100 static void _ecore_exe_pipe_error_cb(void *data, void *buf, unsigned int size);
102 EAPI int ECORE_EXE_EVENT_ADD = 0;
103 EAPI int ECORE_EXE_EVENT_DEL = 0;
104 EAPI int ECORE_EXE_EVENT_DATA = 0;
105 EAPI int ECORE_EXE_EVENT_ERROR = 0;
108 _ecore_exe_init(void)
110 ECORE_EXE_EVENT_ADD = ecore_event_type_new();
111 ECORE_EXE_EVENT_DEL = ecore_event_type_new();
112 ECORE_EXE_EVENT_DATA = ecore_event_type_new();
113 ECORE_EXE_EVENT_ERROR = ecore_event_type_new();
117 _ecore_exe_shutdown(void)
120 ecore_exe_free(exes);
123 static int run_pri = NORMAL_PRIORITY_CLASS;
126 ecore_exe_run_priority_set(int pri)
130 case ECORE_EXE_WIN32_PRIORITY_IDLE:
131 run_pri = IDLE_PRIORITY_CLASS;
133 case ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL:
134 run_pri = BELOW_NORMAL_PRIORITY_CLASS;
136 case ECORE_EXE_WIN32_PRIORITY_NORMAL:
137 run_pri = NORMAL_PRIORITY_CLASS;
139 case ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL:
140 run_pri = ABOVE_NORMAL_PRIORITY_CLASS;
142 case ECORE_EXE_WIN32_PRIORITY_HIGH:
143 run_pri = HIGH_PRIORITY_CLASS;
145 case ECORE_EXE_WIN32_PRIORITY_REALTIME:
146 run_pri = REALTIME_PRIORITY_CLASS;
154 ecore_exe_run_priority_get(void)
158 case IDLE_PRIORITY_CLASS:
159 return ECORE_EXE_WIN32_PRIORITY_IDLE;
160 case BELOW_NORMAL_PRIORITY_CLASS:
161 return ECORE_EXE_WIN32_PRIORITY_BELOW_NORMAL;
162 case NORMAL_PRIORITY_CLASS:
163 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
164 case ABOVE_NORMAL_PRIORITY_CLASS:
165 return ECORE_EXE_WIN32_PRIORITY_ABOVE_NORMAL;
166 case HIGH_PRIORITY_CLASS:
167 return ECORE_EXE_WIN32_PRIORITY_HIGH;
168 case REALTIME_PRIORITY_CLASS:
169 return ECORE_EXE_WIN32_PRIORITY_REALTIME;
170 /* default should not be reached */
172 return ECORE_EXE_WIN32_PRIORITY_NORMAL;
177 ecore_exe_run(const char *exe_cmd, const void *data)
179 return ecore_exe_pipe_run(exe_cmd, 0, data);
183 ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
186 PROCESS_INFORMATION pi;
187 Ecore_Exe_Event_Add *e;
191 exe = calloc(1, sizeof(Ecore_Exe));
195 if ((flags & ECORE_EXE_PIPE_AUTO) && (!(flags & ECORE_EXE_PIPE_ERROR))
196 && (!(flags & ECORE_EXE_PIPE_READ)))
197 /* We need something to auto pipe. */
198 flags |= ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_ERROR;
201 if (exe->flags & ECORE_EXE_PIPE_READ)
202 if (!_ecore_exe_win32_pipes_set(exe))
205 if (exe->flags & ECORE_EXE_PIPE_WRITE)
206 if (!_ecore_exe_win32_pipes_set(exe))
209 if (exe->flags & ECORE_EXE_PIPE_ERROR)
210 if (!_ecore_exe_win32_pipes_set(exe))
213 if ((exe->flags & ECORE_EXE_USE_SH) ||
214 ((ret = strrstr(exe_cmd, ".bat")) && (ret[4] == '\0')))
217 snprintf(buf, PATH_MAX, "cmd.exe /c %s", exe_cmd);
218 exe->cmd = strdup(buf);
221 exe->cmd = strdup(exe_cmd);
226 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
228 ZeroMemory(&si, sizeof(STARTUPINFO));
229 si.cb = sizeof(STARTUPINFO);
230 si.hStdOutput = exe->pipe_read.child_pipe_x;
231 si.hStdInput = exe->pipe_write.child_pipe;
232 si.hStdError = exe->pipe_error.child_pipe_x;
233 si.dwFlags |= STARTF_USESTDHANDLES;
235 /* FIXME: gerer la priorite */
237 if (!CreateProcess(NULL, exe->cmd, NULL, NULL, EINA_TRUE,
238 run_pri | CREATE_SUSPENDED, NULL, NULL, &si, &pi))
241 /* be sure that the child process is running */
242 /* FIXME: This does not work if the child is an EFL-based app */
243 /* if (WaitForInputIdle(pi.hProcess, INFINITE) == WAIT_FAILED) */
244 /* goto free_exe_cmd; */
246 ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE);
247 exe->process = pi.hProcess;
248 exe->process_thread = pi.hThread;
249 exe->process_id = pi.dwProcessId;
250 exe->thread_id = pi.dwThreadId;
251 exe->data = (void *)data;
253 if (!(exe->process2 = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SUSPEND_RESUME | PROCESS_TERMINATE | SYNCHRONIZE,
254 EINA_FALSE, pi.dwProcessId)))
257 exe->h_close = ecore_main_win32_handler_add(exe->process2, _ecore_exe_close_cb, exe);
258 if (!exe->h_close) goto close_process2;
260 if (ResumeThread(exe->process_thread) == ((DWORD)-1))
263 exes = (Ecore_Exe *)eina_inlist_append(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
265 e = (Ecore_Exe_Event_Add *)calloc(1, sizeof(Ecore_Exe_Event_Add));
266 if (!e) goto delete_h_close;
269 ecore_event_add(ECORE_EXE_EVENT_ADD, e,
270 _ecore_exe_event_add_free, NULL);
275 ecore_main_win32_handler_del(exe->h_close);
277 CloseHandle(exe->process2);
279 CloseHandle(exe->process_thread);
280 CloseHandle(exe->process);
284 _ecore_exe_win32_pipes_close(exe);
291 ecore_exe_callback_pre_free_set(Ecore_Exe *exe, Ecore_Exe_Cb func)
293 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
295 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE,
296 "ecore_exe_callback_pre_free_set");
299 exe->pre_free_cb = func;
303 ecore_exe_send(Ecore_Exe *exe, const void *data, int size)
307 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
309 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_send");
313 if (exe->close_stdin)
315 ERR("Ecore_Exe %p stdin is closed! Cannot send %d bytes from %p",
320 if (!exe->pipe_write.child_pipe)
322 ERR("Ecore_Exe %p created without ECORE_EXE_PIPE_WRITE! "
323 "Cannot send %d bytes from %p", exe, size, data);
327 buf = realloc(exe->pipe_write.data_buf, exe->pipe_write.data_size + size);
330 exe->pipe_write.data_buf = buf;
331 memcpy((char *)exe->pipe_write.data_buf + exe->pipe_write.data_size, data, size);
332 exe->pipe_write.data_size += size;
334 /* if (exe->pipe_write.) */
335 /* ecore_main_fd_handler_active_set(exe->pipe_write.h, ECORE_FD_WRITE); */
341 ecore_exe_close_stdin(Ecore_Exe *exe)
343 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
345 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_close_stdin");
348 exe->close_stdin = 1;
351 /* Not used on Windows */
353 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__)
357 EAPI Ecore_Exe_Event_Data *
358 ecore_exe_event_data_get(Ecore_Exe *exe, Ecore_Exe_Flags flags)
360 Ecore_Exe_Event_Data *e = NULL;
361 unsigned char *inbuf;
364 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
366 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_event_data_get");
370 /* Sort out what sort of event we are, */
371 /* And get the data. */
372 if (flags & ECORE_EXE_PIPE_READ)
374 inbuf = exe->pipe_read.data_buf;
375 inbuf_num = exe->pipe_read.data_size;
376 exe->pipe_read.data_buf = NULL;
377 exe->pipe_read.data_size = 0;
381 inbuf = exe->pipe_error.data_buf;
382 inbuf_num = exe->pipe_error.data_size;
383 exe->pipe_error.data_buf = NULL;
384 exe->pipe_error.data_size = 0;
387 e = calloc(1, sizeof(Ecore_Exe_Event_Data));
399 ecore_exe_event_data_free(Ecore_Exe_Event_Data *e)
408 ecore_exe_free(Ecore_Exe *exe)
412 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
414 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_free");
420 if (exe->pre_free_cb)
421 exe->pre_free_cb(data, exe);
423 CloseHandle(exe->process2);
424 CloseHandle(exe->process_thread);
425 CloseHandle(exe->process);
427 _ecore_exe_win32_pipes_close(exe);
428 exes = (Ecore_Exe *)eina_inlist_remove(EINA_INLIST_GET(exes), EINA_INLIST_GET(exe));
429 ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
430 if (exe->tag) free(exe->tag);
437 ecore_exe_pid_get(const Ecore_Exe *exe)
439 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
441 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pid_get");
444 return exe->process_id;
448 ecore_exe_tag_set(Ecore_Exe *exe, const char *tag)
450 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
452 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_set");
457 exe->tag = strdup(tag);
461 ecore_exe_tag_get(const Ecore_Exe *exe)
463 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
465 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_tag_get");
472 ecore_exe_cmd_get(const Ecore_Exe *exe)
474 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
476 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_cmd_get");
483 ecore_exe_data_get(const Ecore_Exe *exe)
485 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
487 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
494 ecore_exe_flags_get(const Ecore_Exe *exe)
496 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
498 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_data_get");
505 ecore_exe_pause(Ecore_Exe *exe)
507 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
509 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_pause");
513 if (exe->is_suspended)
516 if (SuspendThread(exe->process_thread) != (DWORD)-1)
517 exe->is_suspended = 1;
521 ecore_exe_continue(Ecore_Exe *exe)
523 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
525 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_continue");
529 if (!exe->is_suspended)
532 if (ResumeThread(exe->process_thread) != (DWORD)-1)
533 exe->is_suspended = 0;
537 ecore_exe_interrupt(Ecore_Exe *exe)
539 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
541 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_interrupt");
545 CloseHandle(exe->process_thread);
546 CloseHandle(exe->process);
547 exe->sig = ECORE_EXE_WIN32_SIGINT;
548 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
552 ecore_exe_quit(Ecore_Exe *exe)
554 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
556 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_quit");
560 CloseHandle(exe->process_thread);
561 CloseHandle(exe->process);
562 exe->sig = ECORE_EXE_WIN32_SIGQUIT;
563 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
567 ecore_exe_terminate(Ecore_Exe *exe)
569 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
571 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_terminate");
575 /* CloseHandle(exe->thread); */
576 CloseHandle(exe->process);
577 exe->sig = ECORE_EXE_WIN32_SIGTERM;
578 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
582 ecore_exe_kill(Ecore_Exe *exe)
584 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
586 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_kill");
590 CloseHandle(exe->process_thread);
591 CloseHandle(exe->process);
592 exe->sig = ECORE_EXE_WIN32_SIGKILL;
593 while (EnumWindows(_ecore_exe_enum_windows_procedure, (LPARAM)exe));
597 ecore_exe_signal(Ecore_Exe *exe, int num __UNUSED__)
599 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
601 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_signal");
609 ecore_exe_hup(Ecore_Exe *exe)
611 if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE))
613 ECORE_MAGIC_FAIL(exe, ECORE_MAGIC_EXE, "ecore_exe_hup");
620 /* FIXME: manage error mode */
622 _ecore_exe_win32_pipe_thread_generic_cb(void *data, Ecore_Exe_Flags flags)
627 char *current_buf = NULL;
629 Ecore_Pipe *ecore_pipe;
630 Ecore_Exe_Event_Data *event;
632 DWORD current_size = 0;
635 exe = (Ecore_Exe *)data;
637 /* Sort out what sort of handler we are. */
638 /* And get any left over data from last time. */
639 if ((exe->flags & ECORE_EXE_PIPE_READ) && (flags == ECORE_EXE_PIPE_READ))
641 child_pipe = exe->pipe_read.child_pipe;
642 ecore_pipe = exe->pipe_read.p;
643 flags = ECORE_EXE_PIPE_READ;
645 else if ((exe->flags & ECORE_EXE_PIPE_ERROR) && (flags == ECORE_EXE_PIPE_ERROR))
647 child_pipe = exe->pipe_error.child_pipe;
648 ecore_pipe = exe->pipe_error.p;
649 flags = ECORE_EXE_PIPE_ERROR;
656 if (!PeekNamedPipe(child_pipe, buf, sizeof(buf), &size, ¤t_size, NULL))
660 current_buf = (char *)malloc(current_size);
663 res = ReadFile(child_pipe, current_buf, current_size, &size, NULL);
664 if (!res || (size == 0))
670 if (current_size != size)
678 if (flags == ECORE_EXE_PIPE_READ)
680 exe->pipe_read.data_buf = current_buf;
681 exe->pipe_read.data_size = current_size;
685 exe->pipe_error.data_buf = current_buf;
686 exe->pipe_error.data_size = current_size;
689 event = ecore_exe_event_data_get(exe, flags);
691 ecore_pipe_write(ecore_pipe, &event, sizeof(event));
701 _ecore_exe_win32_pipe_thread_read_cb(void *data)
703 return _ecore_exe_win32_pipe_thread_generic_cb(data, ECORE_EXE_PIPE_READ);
707 _ecore_exe_win32_pipe_thread_error_cb(void *data)
709 return _ecore_exe_win32_pipe_thread_generic_cb(data, ECORE_EXE_PIPE_ERROR);
713 _ecore_exe_win32_pipes_set(Ecore_Exe *exe)
715 SECURITY_ATTRIBUTES sa;
719 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
720 sa.bInheritHandle = EINA_TRUE;
721 sa.lpSecurityDescriptor = NULL;
723 if (!CreatePipe(&child_pipe, &child_pipe_x, &sa, 0))
725 if (exe->flags & ECORE_EXE_PIPE_WRITE)
727 if (!SetHandleInformation(child_pipe_x, HANDLE_FLAG_INHERIT, 0))
732 if (!SetHandleInformation(child_pipe, HANDLE_FLAG_INHERIT, 0))
736 if (exe->flags & ECORE_EXE_PIPE_READ)
738 exe->pipe_read.child_pipe = child_pipe;
739 exe->pipe_read.child_pipe_x = child_pipe_x;
740 exe->pipe_read.p = ecore_pipe_add(_ecore_exe_pipe_read_cb, exe);
741 exe->pipe_read.thread = CreateThread(NULL, 0,
742 _ecore_exe_win32_pipe_thread_read_cb,
745 else if (exe->flags & ECORE_EXE_PIPE_WRITE)
747 exe->pipe_write.child_pipe = child_pipe;
748 exe->pipe_write.child_pipe_x = child_pipe_x;
749 /* exe->pipe_write.thread = CreateThread(NULL, 0, */
750 /* _ecore_exe_win32_pipe_thread_cb, */
755 exe->pipe_error.child_pipe = child_pipe;
756 exe->pipe_error.child_pipe_x = child_pipe_x;
757 exe->pipe_error.p = ecore_pipe_add(_ecore_exe_pipe_error_cb, exe);
758 exe->pipe_error.thread = CreateThread(NULL, 0,
759 _ecore_exe_win32_pipe_thread_error_cb,
766 CloseHandle(child_pipe);
767 CloseHandle(child_pipe_x);
773 _ecore_exe_win32_pipes_close(Ecore_Exe *exe)
775 if (exe->flags & ECORE_EXE_PIPE_READ)
777 if (exe->pipe_read.child_pipe)
779 CloseHandle(exe->pipe_read.child_pipe);
780 exe->pipe_read.child_pipe = NULL;
782 if (exe->pipe_read.child_pipe_x)
784 CloseHandle(exe->pipe_read.child_pipe_x);
785 exe->pipe_read.child_pipe_x = NULL;
789 if (exe->flags & ECORE_EXE_PIPE_WRITE)
791 if (exe->pipe_write.child_pipe)
793 CloseHandle(exe->pipe_write.child_pipe);
794 exe->pipe_write.child_pipe = NULL;
796 if (exe->pipe_write.child_pipe_x)
798 CloseHandle(exe->pipe_write.child_pipe_x);
799 exe->pipe_write.child_pipe_x = NULL;
803 if (exe->flags & ECORE_EXE_PIPE_ERROR)
805 if (exe->pipe_error.child_pipe)
807 CloseHandle(exe->pipe_error.child_pipe);
808 exe->pipe_error.child_pipe = NULL;
810 if (exe->pipe_error.child_pipe_x)
812 CloseHandle(exe->pipe_error.child_pipe_x);
813 exe->pipe_error.child_pipe_x = NULL;
819 _ecore_exe_thread_procedure(LPVOID data __UNUSED__)
821 GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
822 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0);
827 _ecore_exe_enum_windows_procedure(HWND window, LPARAM data)
832 exe = (Ecore_Exe *)data;
833 thread_id = GetWindowThreadProcessId(window, NULL);
835 if (thread_id == exe->thread_id)
837 /* Ctrl-C or Ctrl-Break */
838 if (CreateRemoteThread(exe->process, NULL, 0,
839 (LPTHREAD_START_ROUTINE)_ecore_exe_thread_procedure, NULL,
842 printf ("remote thread\n");
846 if ((exe->sig == ECORE_EXE_WIN32_SIGINT) ||
847 (exe->sig == ECORE_EXE_WIN32_SIGQUIT))
849 printf ("int or quit\n");
853 /* WM_CLOSE message */
854 PostMessage(window, WM_CLOSE, 0, 0);
855 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
861 /* WM_QUIT message */
862 PostMessage(window, WM_QUIT, 0, 0);
863 if (WaitForSingleObject(exe->process, ECORE_EXE_WIN32_TIMEOUT) == WAIT_OBJECT_0)
870 if (CreateRemoteThread(exe->process, NULL, 0,
871 (LPTHREAD_START_ROUTINE)ExitProcess, NULL,
874 printf ("remote thread 2\n");
878 if (exe->sig == ECORE_EXE_WIN32_SIGTERM)
884 TerminateProcess(exe->process, 0);
893 _ecore_exe_event_add_free(void *data __UNUSED__, void *ev)
895 Ecore_Exe_Event_Add *e;
897 e = (Ecore_Exe_Event_Add *)ev;
902 _ecore_exe_event_del_free(void *data __UNUSED__, void *ev)
904 Ecore_Exe_Event_Del *e;
906 e = (Ecore_Exe_Event_Del *)ev;
908 ecore_exe_free(e->exe);
913 _ecore_exe_event_exe_data_free(void *data __UNUSED__, void *ev)
915 Ecore_Exe_Event_Data *e;
917 e = (Ecore_Exe_Event_Data *)ev;
918 ecore_exe_event_data_free(e);
922 _ecore_exe_close_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
924 Ecore_Exe_Event_Del *e;
928 e = calloc(1, sizeof(Ecore_Exe_Event_Del));
931 exe = (Ecore_Exe *)data;
933 if (GetExitCodeProcess(exe->process2, &exit_code))
935 e->exit_code = exit_code;
942 msg = evil_last_error_get();
946 e->pid = exe->process_id;
949 ecore_event_add(ECORE_EXE_EVENT_DEL, e,
950 _ecore_exe_event_del_free, NULL);
956 _ecore_exe_pipe_read_cb(void *data, void *buf, unsigned int size)
958 Ecore_Exe_Event_Data *e;
960 e = *((Ecore_Exe_Event_Data **)buf);
962 ecore_event_add(ECORE_EXE_EVENT_DATA, e,
963 _ecore_exe_event_exe_data_free,
968 _ecore_exe_pipe_write_cb(void *data, Ecore_Win32_Handler *wh __UNUSED__)
970 char buf[READBUFSIZ];
975 exe = (Ecore_Exe *)data;
977 res = WriteFile(exe->pipe_write.child_pipe_x, buf, READBUFSIZ, &num_exe, NULL);
978 if (!res || num_exe == 0)
980 /* FIXME: what to do here ?? */
983 if (exe->close_stdin == 1)
985 if (exe->pipe_write.h)
987 ecore_main_win32_handler_del(exe->pipe_write.h);
988 exe->pipe_write.h = NULL;
990 exe->pipe_write.h = NULL;
991 CloseHandle(exe->pipe_write.child_pipe);
992 exe->pipe_write.child_pipe = NULL;
999 _ecore_exe_pipe_error_cb(void *data, void *buf, unsigned int size)
1001 Ecore_Exe_Event_Data *e;
1003 e = *((Ecore_Exe_Event_Data **)buf);
1005 ecore_event_add(ECORE_EXE_EVENT_ERROR, e,
1006 _ecore_exe_event_exe_data_free,