LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2007, 10:07 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Rep: Reputation: 30
Howto execute a command in C if argv[1] is equal to -A


Hi,

I want to execute a command when the first argument of a C program I am writing, is equal to -A.

Can someone show me how that can be done? I am starting with C and I am unable to achieve this myself.

Thanks

Ben
 
Old 02-15-2007, 10:35 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
maybe like this?

Code:
int main(int argc, const char *argv[])
{
  if (strcmp(argv[1],"-A") == 0)
    system("command...");
}
 
Old 02-15-2007, 10:49 AM   #3
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Guttorm
maybe like this?

Code:
int main(int argc, const char *argv[])
{
  if (strcmp(argv[1],"-A") == 0)
    system("command...");
}
Thanks!! It works indeed.

Regards,

Ben
 
Old 02-15-2007, 10:09 PM   #4
wee-face
LQ Newbie
 
Registered: Jan 2007
Posts: 17

Rep: Reputation: 0
Another function you might want to look into is popen(), if you're
familiar with file I/O it will be a breeze.
 
Old 02-16-2007, 03:06 AM   #5
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by wee-face
Another function you might want to look into is popen(), if you're
familiar with file I/O it will be a breeze.
Thanks wee-face. I will take a look at it.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i execute the command? kensim00 Linux - Newbie 9 06-29-2007 03:06 PM
howto execute for loop on remote mach using shell script dsids Linux - Newbie 1 08-22-2006 03:07 AM
howto re-execute dhcp without re-booting? minike Slackware 5 04-23-2006 02:57 PM
execute custom made script on startup howto ALInux Linux - General 7 02-07-2006 01:25 PM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration