Results 1 to 4 of 4
What is the way to get data from shell variables into a GTK+ 2.0 program?
If I have a shell variable "svar1" and an environment variable "ENV1", what is the ...
- 06-10-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 39
Get data from shell variable into GTK+ 2.0
What is the way to get data from shell variables into a GTK+ 2.0 program?
If I have a shell variable "svar1" and an environment variable "ENV1", what is the way to get the value of "svar1" into a GTK+ 2.0 program variable "int i1" and to get the string of "ENV1" into "char buf[ ]"?
- 06-10-2008 #2
You can pick up environmental variables in any C program by using the getenv() function. You give it the name of the variable as an argument and it returns a pointer to the value. if I were you, I'd use that pointer for subsequent access, not put it in a fixed-length buffer.
Shell variables other than environmental ones only have value inside the script that defined them. Are you going to launch your program from inside a script? If so, you can pass $svar1 to it as an argument."I'm just a little old lady; don't try to dazzle me with jargon!"
- 06-10-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 39
No, I had not planned on doing that. With the program name being "program" and inside the /bin/bash shell:Are you going to launch your program from inside a script?
> svar1=10.
> echo $svar1
10
> program
< how can "program" put the "10" into the "int i"?
Thx.getenv() function.
- 06-11-2008 #4
Presumably you want to define svar1 earlier in the session, then reference it later on in your program. I can think of two ways to do it. One is to export the variable to your environment and have the program reference it via getenv. The other is to pass it as a command-line argument
and then have something like:Code:program $svar1
inside your program.Code:integer_var = atoi(argv[1]);
I'd be interested to know if anyone else can give us a third method."I'm just a little old lady; don't try to dazzle me with jargon!"


Reply With Quote
