Find the answer to your Linux question:
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 ...
  1. #1
    Just 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
    Code:
    char * args[10][8];
    so the first block(10) represents the different commands in the command family(
    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
    Code:
    char *argsx[] = {"ls", "-l", (char *) 0 };
    but when i try to create on the fly from the argument array at top like this
    Code:
    while(1)
    		{
    		args1[c] = args[c][0];
    		if(args[c][0] == NULL)
    		break;
    		c++;
    		}
    
    execv(str1, args1);
    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?

    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

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,499
    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!

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    9
    yeah, the problem was a new line character in the original string from fgets function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •