UNIX commands in C

Ronald Hayden ron at well.sf.ca.us
Wed May 1 15:07:42 AEST 1991


jtanner at jack.sns.com (Jason Tanner) writes:


>    I have been programming C for a while on IBM compats. using Turbo-C
>from Borland. Now I would like to move up to programing C in the UNIX
>enviroment. I know how to use all the regular C commands but I would like
>to know how to use UNIX commands from within a C program. For example
>to have the option to show who is online from within a program. I dont
>want this done with a shell escape I want it to be an potion like from a
>menu/list.
>   Thank you in advance.  Please Email or post all replies.
>-- 

There are actually several ways to do this (check out the book C
Programming In a UNIX Environment for a complete discussion), but for
a simple command such as "who", you can simply:


#include <stdio.h>

main ()
{
 printf("\nTesting the UNIX 'who' command --\n");
 system("who");
 printf("\nDone.\n");
 exit(1);
}



More information about the Comp.lang.c mailing list