Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > The Linux Kernel
Reload this Page How to use unix command in c program
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

The Linux Kernel Compiling, theory, programming or other discussion about the linux kernel

Reply
 
Thread Tools Display Modes
Old 02-22-2008   #1 (permalink)
pnpvivek
Just Joined!
 
Join Date: Feb 2008
Posts: 18
How to use unix command in c program

Hi,
I am new to Linux world.I know the basic commands in Unix.and I want to develop a c program using Unix command .plz send me the example program

thanks to all.
vivek
pnpvivek is offline   Reply With Quote
Old 02-22-2008   #2 (permalink)
vthanki
Just Joined!
 
Join Date: Feb 2008
Posts: 7
#include <stdlib.h>
int main()
{
system("/bin/ls");
return 0;
}

hope it helps
vthanki is offline   Reply With Quote
Old 02-25-2008   #3 (permalink)
brahan_7
Just Joined!
 
brahan_7's Avatar
 
Join Date: Dec 2007
Location: Deep South
Posts: 26
int main(int argc, char *argv[])
{
char* userId;
char buffer[10];

if(argc != 2) {
cout << "usage: " << argv[0] << " cmd line arg.\n";
exit(0);

}
userId = argv[1];
sprintf (buffer, "findName.sh %s", userId);
system(buffer);

return 0;

}

This program finds the full name that matches a userId entered as a cmd line arg...
All you need to worry about is the sprintf and system parts and use them as an example.

This basically works by alowing you to represent your commands as text and them use a system call to run them the system call goes out like anyother function and will return back to the where it left off just like anyother function.

Also check out these websites:
http://www.cplusplus.com/reference/c...o/sprintf.html
http://www.cplusplus.com/reference/c...ib/system.html

Post anymore questions!
brahan_7 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ipv6 and networking questions cnahas Redhat / Fedora Linux Help 0 11-16-2007 02:52 PM
Different execution behaviour of a program executed from rc.local ajaymeka Linux Programming & Scripting 2 08-16-2007 06:13 AM
Add/remove program error jasond123 Ubuntu Help 3 05-27-2007 04:10 PM
Netstat Newb dmbomb Slackware Linux Help 1 04-30-2006 04:25 PM




All times are GMT. The time now is 01:02 PM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0