Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!emory!mephisto!prism!gt0178a From: gt0178a@prism.gatech.EDU (BURNS) Newsgroups: comp.unix.questions Subject: Re: How to issue a C SHELL command with Message-ID: <12585@hydra.gatech.EDU> Date: 15 Aug 90 07:04:54 GMT References: <22000008@ux1.cso.uiuc.edu> Organization: Georgia Institute of Technology Lines: 40 in article <22000008@ux1.cso.uiuc.edu>, kahlers@ux1.cso.uiuc.edu says: Nf-ID: #R:<25279:26:ux1.cso.uiuc.edu:22000008:000:429 Nf-From: ux1.cso.uiuc.edu!kahlers Aug 14 16:42:00 1990 >> How can I issue a statment that executes a C SHELL command within a C program? >> I would appreciate any helps. > > You can use the "system" call. Use "man system" for more info. The system call uses bourne sh, so this won't work unless the command you pass to system is 'csh mycommand', which would be inefficient (sh calls csh calls mycommand). Probably a skeleton like the following is needed: #include #include char mycommand[] = "history"; main() { union wait status; int pid,some_status=1,some_other_status=2; /* char mycommand[10] = "history";*/ fflush(0); /* optional - check syntax on your system */ switch (fork()) { case -1: perror(); exit(some_status); /* fork failed */ break; case 0: /* child proc */ execlp("/bin/csh","csh","-c",mycommand,(char *) 0); /* the -c is used when mycommand is a builtin */ exit(some_other_status); /* exec failed */ break; default: /* parent */ pid=wait(status); break; } } -- BURNS,JIM Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a Internet: gt0178a@prism.gatech.edu