![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to? launch command with string of command line options | TinCanFury | Shell Programming and Scripting | 5 | 04-28-2008 06:06 PM |
| find command sort options? | mavsman | UNIX for Dummies Questions & Answers | 6 | 04-01-2008 03:20 PM |
| Associated array from command line options | jperret | Shell Programming and Scripting | 1 | 01-10-2008 05:16 PM |
| Split Command options | mohdtausifsh | UNIX for Advanced & Expert Users | 7 | 10-04-2006 07:28 AM |
| Find command with prune and exec options | Sebarry | UNIX for Dummies Questions & Answers | 2 | 06-19-2006 04:07 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Executing command line options
Can someone please tell me how to modify/add to this code so that it recognizes UNIX command options (all beginning with "-") and executes the command with options?
Code:
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int i;
system("stty -echo");
for(i=1; i<argc; i++)
{
printf("The command %s is executed.\n", argv[i]);
system(argv[i]);
}
system("stty echo");
return 0;
}
|
|
||||
|
try this one
Can you try this one ??
#include "stdio.h" #include "stdlib.h" #include "string.h" void main(int argc, char **argv) { char str[30]; if (argv[2][0] == '-') { strcpy(str,argv[1]); strcat(str," "); strcat(str,argv[2]); system (str); } }//end of main or void main(int argc, char **argv) { system(argv[1]); } for second case, you need to give input as say "ls -l" within double quotes. You can have any combination for this. Like let us assume "a.out" is the binary then ./a.out "who | wc -l" also works for the second option.,.... bye, sharath |
|
||||
|
ANSI C says 'int main()'. Ofcourse, to avoid compiler warnings you can use 'void main()', but that is incorrect. The OS might be wanting a return value from the terminated program, and when you are not returning any value to it, a junk value might be returned to your OS, and the results could be unpredictable.
See this |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|