It is currently Mon, 08 Aug 2022 20:51:05 GMT



 
Author Message
 How do i transfer the contents of shell variable to a variable used in C program
Hi,
  Is it possible to transfer the contents of the shell variable to a
variable used in C program. If so, how can i achieve this.
  Thanks in advance.
caroline.c


 Fri, 09 Jan 2004 19:04:06 GMT   
 How do i transfer the contents of shell variable to a variable used in C program

The C program could use popen() to run the script, and read its
output, then assign the output of the script to some internal
variable.



 Fri, 09 Jan 2004 20:02:57 GMT   
 How do i transfer the contents of shell variable to a variable used in C program

I am not sure what you want. If you want to pass a env-variable to a
c-program you could just pass the variable as a command line argument:

myCprogram $MY_ENV_VAR

If you want to use env-variables inside your c-program you could use the
function

char *getenv(const char *name)

from <stdlib.h>.

Uwe

--



 Fri, 09 Jan 2004 20:55:31 GMT   
 How do i transfer the contents of shell variable to a variable used in C program
On 23 Jul 2001 04:04:06 -0700, carosy...@yahoo.com (caroline) wrote:

Use the getenv() call.

For instance,

 # include <stdlib.h>

  {
     char *string;

     if ((*string = getenv("PATH")) != NULL)
       printf("Your PATH environment variable is set to %s\n",string);
     else
       printf("Gasp!! Your PATH is not set!!\n");

  }

Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group
(Lew_Pitc...@td.com)

(Opinions expressed are my own, not my employer's.)



 Fri, 09 Jan 2004 21:20:13 GMT   
 
   [ 4 post ] 

Similar Threads

1. file contents into variable, or global variable from shell script

2. shell scripting: echoing contents of contents of variable

3. getting environment variables from c shell using Bourne shell

4. Help: Shell variable content stripping !

5. file contents into shell/env variable

6. Executing contents of variable in shell script

7. Listing contents of shell variable thats = a directory path

8. Q: getting variable contents in bourne shell

9. Creating shell variable containing substring of another variable.


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software