Find the answer to your Linux question:
Results 1 to 4 of 4
Hi all, I am trying to take argument from command line ic a Cprogram an give that argument as an argument to a script file which is called in that ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    8

    calling script with argument from C program



    Hi all,
    I am trying to take argument from command line ic a Cprogram an give that argument as an argument to a script file which is called in that C program.Is it possible for example:
    my C program is:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    int main(int argc, char **argv)
    {
    int size;
    char *t=NULL;
    size=strlen(argv[1]);
    t=(char *)malloc(sizeof(char)*size);
    strcpy(t,argv[1]);
    printf("%s",t);
    system("./temp1.sh ______");
    }

    I want to fill that blank with thevalue of argv[1] such that it will act as an argument for temp1.sh.
    Please help.......

  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
    I have to ask, is this a class assignment?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Posts
    8
    Nop its not a class assignment, I have accomplished it by using string concatenation and passing the string to the system() but is there some direct way to do that????

  4. #4
    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
    You can fork and run one of the exec() functions which will allow you to pass the arguments and such in a more rational way. See the man page for exec, execlp, execv, et al.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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