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, ...
- 02-11-2009 #1Just 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 :-
it seems the C compiler could not understand the ../testdirectory/test command since it is use in bash script as cd ../testdirectory/test.Code:execlp(../testdirectory/test, pipe0, pipe1, NULL)
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.
- 02-11-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
try like this:
system ("cd ../testdirectory;./test");
K&R p.167the sun is new every day (heraclitus)
- 02-12-2009 #3Just 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
- 02-12-2009 #4Just 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.
- 02-12-2009 #5Just 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.


Reply With Quote