How to issue a C SHELL command with
BURNS
gt0178a at prism.gatech.EDU
Wed Aug 15 17:04:54 AEST 1990
in article <22000008 at ux1.cso.uiuc.edu>, kahlers at 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 <stdio.h>
#include <sys/wait.h>
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 at prism.gatech.edu
More information about the Comp.unix.questions
mailing list