shell commands in c program

Hi All,

I want to include some shell commands in my c program in linux.
please help..

thanks in advance
esham

Go through the man pages of popen and pclose. These allow you to execute commands and read/write from/to them.

Also look at the man page for system(). It lets you run a command easily, but you can't do i/o to or from the command.

you could also see the manual page of exevp .

system() functions work fine.

But iam not able to give input for any commands

for eg:

can i give

var=/home/esham
ret=system("ls $var");

Please help..

Esham,

You cannot assign "var=/home/esham" in C, you are talking about shell scripting. In C you would have variables like

char var[]="/home/esham";

It would help if you tell what exactly you want to do and how you are trying to do it.