/*-------------------------------------------------------------------------*/ /* Pipeline.c : routines for creating training and sampling programs */ /* running underneath xtdnn. */ /*-------------------------------------------------------------------------*/ #include int talkto(cmd) char *cmd; { int to_child[2], /* pipe descriptors from parent to child */ to_parent[2]; /* pipe descriptors from child to parent */ int pid, value; pipe(to_child); pipe(to_parent); if ((pid = fork()) == 0) { close(0); dup(to_child[0]); close(1); dup(to_parent[1]); close(to_child[0]); close(to_child[1]); close(to_parent[0]); close(to_parent[1]); value = execlp(cmd, cmd, NULL); return(value); } else if (pid > 0) { close(0); dup(to_parent[0]); close(1); dup(to_child[1]); setbuf(stdout, NULL); close(to_child[0]); close(to_child[1]); close(to_parent[0]); close(to_parent[1]); return(0); } else return(2); }