How to execute shell command without using system command in C-langauage? wirte a program execute ls -l and redirect the output to a file, without using system command ?

Questions by gsivaprakashreddy   answers by gsivaprakashreddy

Showing Answers 1 - 3 of 3 Answers

Raj Sharma

  • Oct 26th, 2007
 

#include<stdio.h>
#include<sys/types.h>
#include<dirent.h>
#include<fcntl.h>
#include<unistd.h>

int main(int argc,char *argv[])
{
 DIR    *dp;
 struct dirent *dirp;

 dp = opendir(argv[1]);

 while((dirp=readdir(dp))!=0)
 printf("%sn",dirp->d_name);

 closedir(dp);
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions