forked from enlightenment/efl
exe pipe example and other exe (no pipe) example. :)
SVN revision: 18951
This commit is contained in:
parent
a0ceee8b51
commit
7475ec3508
|
@ -4,7 +4,8 @@ timer_example \
|
||||||
event_handler_example \
|
event_handler_example \
|
||||||
args_example \
|
args_example \
|
||||||
list_example \
|
list_example \
|
||||||
list_destroy_example
|
list_destroy_example \
|
||||||
|
exe_example
|
||||||
|
|
||||||
if BUILD_ECORE_CON
|
if BUILD_ECORE_CON
|
||||||
CON_EXAMPLES = con_server_example con_client_example
|
CON_EXAMPLES = con_server_example con_client_example
|
||||||
|
@ -39,6 +40,7 @@ list_example_SOURCES = list_example.c
|
||||||
list_destroy_example_SOURCES = list_destroy_example.c
|
list_destroy_example_SOURCES = list_destroy_example.c
|
||||||
event_handler_example_SOURCES = event_handler_example.c
|
event_handler_example_SOURCES = event_handler_example.c
|
||||||
args_example_SOURCES = args_example.c
|
args_example_SOURCES = args_example.c
|
||||||
|
exe_example_SOURCES = exe_example.c
|
||||||
|
|
||||||
if BUILD_ECORE_CON
|
if BUILD_ECORE_CON
|
||||||
con_server_example_SOURCES = con_server_example.c
|
con_server_example_SOURCES = con_server_example.c
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/* Timer example.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Ecore.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
Ecore_Exe *exe0 = NULL;
|
||||||
|
Ecore_Exe *exe1 = NULL;
|
||||||
|
Ecore_Exe *exe2 = NULL;
|
||||||
|
Ecore_Exe *exe3 = NULL;
|
||||||
|
|
||||||
|
static int
|
||||||
|
exe_data(void *data, int type, void *event)
|
||||||
|
{
|
||||||
|
Ecore_Event_Exe_Data *ev;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ev = event;
|
||||||
|
printf(" [*] DATA RET EXE %p - %p [%i bytes]\n", ev->exe, ev->data, ev->size);
|
||||||
|
for (i = 0; i < ev->size; i++)
|
||||||
|
putchar(((unsigned char *)ev->data)[i]);
|
||||||
|
printf("\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
exe_exit(void *data, int type, void *event)
|
||||||
|
{
|
||||||
|
Ecore_Event_Exe_Exit *ev;
|
||||||
|
|
||||||
|
ev = event;
|
||||||
|
printf(" [*] EXE EXIT: %p\n", ev->exe);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
ecore_init();
|
||||||
|
ecore_event_handler_add(ECORE_EVENT_EXE_DATA, exe_data, NULL);
|
||||||
|
ecore_event_handler_add(ECORE_EVENT_EXE_EXIT, exe_exit, NULL);
|
||||||
|
exe0 = ecore_exe_run("/bin/uname -a", NULL);
|
||||||
|
|
||||||
|
exe1 = ecore_exe_pipe_run("/bin/sh",
|
||||||
|
ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE,
|
||||||
|
NULL);
|
||||||
|
ecore_exe_pipe_write(exe1, "ls\n", 3);
|
||||||
|
exe2 = ecore_exe_pipe_run("/usr/bin/find / -print",
|
||||||
|
ECORE_EXE_PIPE_READ,
|
||||||
|
NULL);
|
||||||
|
exe3 = ecore_exe_pipe_run("/bin/cat",
|
||||||
|
ECORE_EXE_PIPE_WRITE,
|
||||||
|
NULL);
|
||||||
|
ecore_exe_pipe_write(exe3, "ls\n", 3);
|
||||||
|
printf(" [*] exe0 = %p (/bin/uname -a)\n", exe0);
|
||||||
|
printf(" [*] exe1 = %p (echo \"ls\" | /bin/sh)\n", exe1);
|
||||||
|
printf(" [*] exe2 = %p (/usr/bin/find / -print)\n", exe2);
|
||||||
|
printf(" [*] exe3 = %p (echo \"ls\" | /bin/cat)\n", exe3);
|
||||||
|
ecore_main_loop_begin();
|
||||||
|
ecore_shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -242,7 +242,7 @@ ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
|
||||||
exe->pid = pid;
|
exe->pid = pid;
|
||||||
exe->flags = flags;
|
exe->flags = flags;
|
||||||
exe->data = (void *)data;
|
exe->data = (void *)data;
|
||||||
exe->cmd = exe_cmd; /* FIXME: should calloc and cpy. */
|
exe->cmd = strdup(exe_cmd);
|
||||||
if (flags & ECORE_EXE_PIPE_READ)
|
if (flags & ECORE_EXE_PIPE_READ)
|
||||||
{
|
{
|
||||||
exe->child_fd_read = readPipe[0];
|
exe->child_fd_read = readPipe[0];
|
||||||
|
@ -254,6 +254,7 @@ ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
|
||||||
if (flags & ECORE_EXE_PIPE_WRITE)
|
if (flags & ECORE_EXE_PIPE_WRITE)
|
||||||
{
|
{
|
||||||
exe->child_fd_write = writePipe[1];
|
exe->child_fd_write = writePipe[1];
|
||||||
|
fcntl(exe->child_fd_write, F_SETFL, O_NONBLOCK); /* FIXME: Check for -1 then errno. */
|
||||||
exe->write_fd_handler = ecore_main_fd_handler_add(exe->child_fd_write,
|
exe->write_fd_handler = ecore_main_fd_handler_add(exe->child_fd_write,
|
||||||
ECORE_FD_WRITE, _ecore_exe_data_write_handler, exe,
|
ECORE_FD_WRITE, _ecore_exe_data_write_handler, exe,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
@ -639,6 +640,7 @@ _ecore_exe_free(Ecore_Exe *exe)
|
||||||
if (exe->read_data_buf) free(exe->read_data_buf);
|
if (exe->read_data_buf) free(exe->read_data_buf);
|
||||||
if (exe->flags & ECORE_EXE_PIPE_READ) close(exe->child_fd_read); /* FIXME: Check for -1 then errno. */
|
if (exe->flags & ECORE_EXE_PIPE_READ) close(exe->child_fd_read); /* FIXME: Check for -1 then errno. */
|
||||||
if (exe->flags & ECORE_EXE_PIPE_WRITE) close(exe->child_fd_write); /* FIXME: Check for -1 then errno. */
|
if (exe->flags & ECORE_EXE_PIPE_WRITE) close(exe->child_fd_write); /* FIXME: Check for -1 then errno. */
|
||||||
|
if (exe->cmd) free(exe->cmd);
|
||||||
|
|
||||||
exes = _ecore_list2_remove(exes, exe);
|
exes = _ecore_list2_remove(exes, exe);
|
||||||
ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
|
ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE);
|
||||||
|
|
Loading…
Reference in New Issue