PLEX86  x86- Virtual Machine (VM) Program
 Plex86  |  CVS  |  Mailing List  |  Download  |  Linux  |  Newsgroups

popen


Your Ad Here

Your Ad Here

Lew Pitcher snip

It took me a bit, but here's an example for a bidi popen(). Note, I haven't written the corresponding pclose(), which should just be a close of both FILE pointers, and a waitpid for the child to terminate.

int myPopen(char *cmd, FILE *io) { int Parent2Child2, Child2Parent2; pidt pid;

return -1;* cant establish pipes *

switch(fork()) { case -1: return -1;* cant fork *

case 0:* child * close(Parent2Child1); dup2(Parent2Child0,0); close(Child2Parent0); dup2(Child2Parent1,1); execlp("bash","bash","-c",cmd,NULL); return -1;

Linux May Hit Single Digit Desktop Marketshare in 5 Years!!! 2373
Correction: Someone who sometimes calls himself "Tomas Dunton" Typical ignorant windoze weenie: He thinks that Linux wishes it were windows. If that were...

default:* parent * close(Child2Parent1); io0 = fdopen(Child2Parent0,"r"); close(Parent2Child0); io1 = fdopen(Parent2Child1,"w"); return 0; } return -1; }

int main(void) { FILE *io2; * io0 is output of child, input to parent * * io1 is input to child, output of parent * int rc; int byte;

rc = myPopen("tr A-Z a-z",io); printf("myPopen() returned %d-n",rc); if (rc == 0) { fprintf(io1,"THIS IS A TEST-n"); fclose(io1);

while ((byte = fgetc(io0)) != EOF) putchar(byte); }

return EXITSUCCESS; }

HTH -- Lew Pitcher



Your Ad Here

List | Previous | Next

Linux May Hit Single Digit Desktop Marketshare in 5 Years!!! 2373

Linux groups from Newsgroups

The #1 Usenet Provider on the Internet

Process end 2371