Tuesday, January 24, 2012

How to run a unix command from a C program

The C function used to run the command is
system();

for eg:
system("ls");
execute ls command whereas

system("pwd");
execute pwd command.

A sample C program

#include<stdio.h>
#include<stdlib.h>
main()
    {
    char c[10]="pwd";
    system(c);
    }

It produces the output as


'pwd' is a unix command for showing the present working directory.

No comments :

Post a Comment