--- libaitio/example/test_exec.c 2013/12/05 17:12:16 1.1.2.6 +++ libaitio/example/test_exec.c 2013/12/08 21:11:54 1.1.2.12 @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include @@ -7,7 +10,9 @@ int main(int argc, char **argv) { prog_t *p; + int f; int ret = 0; + char str[BUFSIZ]; if (argc < 2) return 1; @@ -16,7 +21,7 @@ main(int argc, char **argv) if (!p) { ELIBERR(io); return 2; - } else if ((ret = io_progCheck(p))) { + } else if ((ret = io_progCheck(p, 0))) { printf("0.exited procs=%d\n", ret); goto end; } else { @@ -24,7 +29,7 @@ main(int argc, char **argv) getchar(); } - ret = io_progCheck(p); + ret = io_progCheck(p, 0); if (ret) { printf("1.exited procs=%d\n", ret); goto end; @@ -43,6 +48,25 @@ main(int argc, char **argv) printf("wait for keystroke %p ", p); getchar(); + +again: + f = io_progAttach(p); + 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;