Results 1 to 3 of 3
hi everyone
i have an array of arguments (such as ls, wc, etc) stored in here
Code:
char * args[10][8];
so the first block(10) represents the different commands in the ...
- 10-31-2009 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 9
need serious help with execv function
hi everyone
i have an array of arguments (such as ls, wc, etc) stored in here
so the first block(10) represents the different commands in the command family(Code:char * args[10][8];

so args[0][0] is ls and args[1][0] is -l for the command family ls -l and so on
i can use execv command easily with a predefined char* args like so
but when i try to create on the fly from the argument array at top like thisCode:char *argsx[] = {"ls", "-l", (char *) 0 };
it won't work although it will for execv(str1, argsx), the predefined one. when i print the contents of args1 and argsx they are the same. what gives?Code:while(1) { args1[c] = args[c][0]; if(args[c][0] == NULL) break; c++; } execv(str1, args1);
i reallllllly need help on this and would appreciate it
thanks
edit:
moreover,
with piping/fork/dup2 such that you can pipe shell commands in their own process,
how can you output to a file(like for the final command) using dup2?
thank you very much
- 10-31-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,961
Is this a school or class project? In any case, your problem is in misunderstanding the meaning of char* args[10][8] and how to initialize multi-dimensional arrays.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 11-01-2009 #3Just Joined!
- Join Date
- Sep 2009
- Posts
- 9
yeah, the problem was a new line character in the original string from fgets function.


Reply With Quote
