Unix Blog !

August 15, 2007

Execute shell commands from a C program

Filed under: C Program — sriram003 @ 7:33 pm

Heres a C Program that use system() function to
execute shell commands:

See man system for more information:

[root@linuxbox C_Programs]# cat test.c
#include
main()
{
printf (“Files More than 10 MB !!\n”);
system(“find . -size +10000k”);
return 0;
}

[root@linuxbox C_Programs]# gcc test.c

[root@linuxbox C_Programs]# ./a.out
Files More than 10 MB !!
./xemacs-packages-extra-20061221-1.fc7.noarch.rpm

Programming C under Unix

Filed under: C Program, Shell Script — sriram003 @ 6:11 pm

Writing a test Program in C (Unix):
====================================
[root@linuxbox C_Programs]# cat test.c
#include
main()
{

printf (“Hello Sriram!!\n”);

return 0;

}

Executing the above :
=====================
[root@linuxbox C_Programs]# gcc test.c

[root@linuxbox C_Programs]# ls
a.out test.c

[root@linuxbox C_Programs]# ./a.out
Hello Sriram!!

Create a free website or blog at WordPress.com.