Results 1 to 7 of 7
Hi,
I write a C program to retrieve some information from the WebLogic Server. To do that I have to set upsome Environment Variables. For that I have a script ...
- 03-06-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 8
how to execute script file unside C program
Hi,
I write a C program to retrieve some information from the WebLogic Server. To do that I have to set upsome Environment Variables. For that I have a script file to set Environment Variables. I want to execute the script file via my C program. Is it Possible?. Please help me.
- 03-06-2008 #2Just Joined!
- Join Date
- Feb 2008
- Posts
- 50
Yes, you can use "system" to execute your any file/shell command/shell script file.. etc. within your c program.
e.g. (i)system("ls -al");
(ii)system("./sample.sh");
Thanks,
Pankaj.
- 03-06-2008 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 03-06-2008 #4
Edit: the rest of this reply is completely wrong because I misread the question. Franklin52's answer is absolutely correct.
What variable? Or do you mean the output of the command?This should not work because the variable is only available in the subshell.
If you mean the output, there is a very simple way to gather the output in your C program after doing the system() call.
First, do the system call thus:
Then read the output file (which you can call something different, of course) in your C program.Code:system("whatever > output.txt");
Two things to keep in mind:
- You should actually do something like this:
and then examine the result code to make sure the program ran successfully. For more details, do this at the command line:Code:int result_code; /* ... */ result_code=system("whatever > output.txt");
If man pages are not installed on your system, google this:Code:man 3 system
Code:man system linux
- There are faster ways to do this whole thing that are less makeshift but are more complex to code.
--
Bill
Old age and treachery will overcome youth and skill.
- You should actually do something like this:
- 03-06-2008 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
If I'm not missing something, the OP want to set some environment variables in his C program with a script. In that case you can use the setenv function.
RegardsCode:man setenv
- 03-06-2008 #6
Oops. Franklin52, your original answer was absolutely correct. My bad.
--
Bill
Old age and treachery will overcome youth and skill.
- 03-07-2008 #7Just Joined!
- Join Date
- Feb 2008
- Posts
- 50
Yes, you are right.. "setenv" is right answer.
Thanks,
Pankaj



