Re: pass enviornment variables to popen

From: wally (root_at_localhost.localdomain)
Date: 01/30/05


Date: Sun, 30 Jan 2005 12:20:19 -0500

sam wrote:

> Hi,
>
> How can I pass enviornment variables to popen() in C?
> I want to do something like this:
> setenv("KEY_CONF", "/usr/local/etc/ssl/conf/openssl.conf", 1);
> popen("openssl <some commandline args> $KEY_CONF", "w");
>
> But the above enviornment variable get removed in calling popen().
> Unless I rewrite popen(), I don't see I can pass the enviornment
> variables to popen().
>
>
> Sam.

why not try something along the lines of:

setenv("KEY_CONF", "/usr/local/etc/ssl/conf/openssl.conf", 1);
...
char *key_conf=getenv("KEY_CONF");
char pipe_command[255];

//although you should probably restrict the size of that array to avoid out
//of bounds in case the KEY_CONF is set to something so big that it wont fit
//here so you can try something along the lines of:
//*pipe_command=malloc(sizeof("openssl <some commandline args> ") + sizeof
(&key_conf));

sprintf(pipe_command("openssl <some commandline args> %s", pipe_command);
pipe_fp=popen(pipe_command, "w");

-- 
WINDOWS: "Where do you want to go today?"
LINUX: "Where do you want to go tommorow?"
BSD: "Are you guys coming or what?"


Relevant Pages

  • Re: pass enviornment variables to popen
    ... sam wrote: ... > How can I pass enviornment variables to popenin C? ... Use popento execute shell scripts where you set and export the environment ... execve() instead using setenv in the child process just prior to execve. ...
    (comp.unix.bsd.freebsd.misc)
  • pass enviornment variables to popen
    ... How can I pass enviornment variables to popenin C? ... But the above enviornment variable get removed in calling popen(). ... Unless I rewrite popen(), I don't see I can pass the enviornment ... Sam. ...
    (comp.unix.bsd.freebsd.misc)