File:
[ELWIX - Embedded LightWeight unIX -] /
libaitio /
example /
test_exec.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs -
revision graph
Sun Dec 15 22:57:20 2013 UTC (11 years, 4 months ago) by
misho
Branches:
MAIN
CVS tags:
io7_4,
io7_3,
io7_2,
io7_1,
io7_0,
io6_9,
io6_8,
IO7_3,
IO7_2,
IO7_1,
IO7_0,
IO6_9,
IO6_8,
IO6_7,
HEAD
version 6.7
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <aitio.h>
#include <sys/wait.h>
int
main(int argc, char **argv)
{
prog_t *p;
int f;
int ret = 0;
char str[BUFSIZ];
if (argc < 2)
return 1;
p = io_progInit(argv[1], 3, 10);
if (!p) {
ELIBERR(io);
return 2;
} else if ((ret = io_progCheck(p, 0))) {
printf("0.exited procs=%d\n", ret);
goto end;
} else {
printf("wait for keystroke %p ", p);
getchar();
}
ret = io_progCheck(p, 0);
if (ret) {
printf("1.exited procs=%d\n", ret);
goto end;
}
printf("last=%d\n", array_Last(p->prog_fds));
ret = io_progGrow(p, 8);
printf("+grow_progs=%d\n", ret);
printf("wait for keystroke %p ", p);
getchar();
ret = io_progVacuum(p, 5);
printf("+vacuum_progs=%d\n", ret);
printf("wait for keystroke %p ", p);
getchar();
again:
f = io_progAttach(p, 0);
printf("f=%d\n", f);
write(f, "v\n", 1);
memset(str, 0, sizeof str);
while (read(f, str, sizeof str) > 0) {
printf(">>> %s", str);
memset(str, 0, sizeof str);
read(0, str, sizeof str);
if (*str == '.')
break;
write(f, str, strlen(str));
}
io_progDetach(p, f);
printf("(r) wait for keystroke %p ", p);
if (getchar() == 'a')
goto again;
end:
io_progDestroy(&p);
return ret;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>