setenv from c

Thomas M. Breuel tmb at talcott.UUCP
Sun Sep 29 12:26:52 AEST 1985


In article <1355 at teddy.UUCP>, jpn at teddy.UUCP writes:
> > Is it possible to set a csh environment variable within a C program?
> 
> In all the replies to this question, I have not yet seen my favorite techniqe
> This only works on BSD 4.X (at least as far as I know).  There is an
> undocumented ioctl() which allows you to push data back onto your input queue
> (i.e. simulate characters typed at the terminal).  Using this technique, one
> can stuff strings like "setenv TERM xxx\n" into the parent shell's input.

The ioctl is documented in tty(4). Generally, your program is unlikely to 
be smart enough to type at whatever I invoke it from (e.g. shell escape from 
ed). Use of this ioctl can cause extremely weird behaviour of programs and
shell scripts. Since it is also non-portable, works only on ttys
and might be abolished altogether, I would strongly recommend *not* to use it.

						Thomas.



More information about the Comp.lang.c mailing list