Find the answer to your Linux question:
Results 1 to 5 of 5
Hi I need your guys help. I have problems so that the C compiler can understand a bash script. I tried to do like this :- Code: execlp(../testdirectory/test, pipe0, pipe1, ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    19

    insert one line bash script in C

    Hi

    I need your guys help. I have problems so that the C compiler can understand a bash script. I tried to do like this :-

    Code:
    execlp(../testdirectory/test, pipe0, pipe1, NULL)
    it seems the C compiler could not understand the ../testdirectory/test command since it is use in bash script as cd ../testdirectory/test.

    how can I make this work. Can I just add a bash script in the execlp() function or I must just define an exact location and the Makefile will take in charge on the directory path during installation.

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    try like this:

    system ("cd ../testdirectory;./test");

    K&R p.167
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    15

    insert one line script in c

    hi,

    first set you current PATH environment variable. then in execvp you give your path in quote and compile.

    For example.

    PATH=$PATH:$PWD
    export $PATH

    execvp("",args...);

    complile

  4. #4
    Just Joined!
    Join Date
    Dec 2007
    Posts
    19
    Thanks for the reply. I have tried using system() but it does not really suits with my program requirement and it doesnt really works in my program. However, for the second method as being described by umeshkmahindrakar, im quite interested to try that implementation but Im quit not clear on how you gave the example.

    1) First set your current path

    What is the data type of PATH? is it #define PATH or a string?

    2)export $PATH.

    which path that must be exported? is it the PATH or $PATH? As I understand, PATH is the one defined in C and $PATH is the one from the shell script.

    3) execvp("", args..)

    In the quote, what data must be in it? the PATH or $PATH. I know i can put my actual path in the quote but it does not solve the problem. The reason I want to do this is because I dont want to put a hard coded path in the execlp() function. I would like it to be more flexible in naming the path and of course is it easy for me or other users to change the directory name and the program still runs as usual.

    Anyway, thanks a lot for your reply. It is really appreciated.

  5. #5
    Just Joined!
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    15

    insert one line script in c

    hi,

    PATH or not defined in the C program

    there are the environment variable. either you can set the environment variable using setenv() system call.
    or

    set the PATH variable in the shell. It will work

    for example
    $PATH=$PATH:$PWD
    $export $PATH

    in your c program just call the execlp or execvp system call with appropriate argument.

Posting Permissions

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