Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 exptools; site ihdev.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!ihdev!pdg From: pdg@ihdev.UUCP (P. D. Guthrie) Newsgroups: net.lang.c Subject: Re: setenv from c Message-ID: <337@ihdev.UUCP> Date: Mon, 30-Sep-85 13:25:29 EDT Article-I.D.: ihdev.337 Posted: Mon Sep 30 13:25:29 1985 Date-Received: Wed, 2-Oct-85 07:33:02 EDT References: <2936@ncsu.UUCP> <6000007@mirror.UUCP> <1355@teddy.UUCP> Reply-To: pdg@ihdev.UUCP (55224-P. D. Guthrie) Organization: AT&T Bell Laboratories Lines: 34 In article <1355@teddy.UUCP> jpn@teddy.UUCP (John P. Nelson) 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. > >A fragment of the code that does the work: > >#include> >eatthis(string) >register char *string; > { > int pendin = LPENDIN; > > noecho(); /* turn off echo mode */ > while (*string) > { > ioctl(0, TIOCSTI, string); /* do the work */ > ++string; > } > echo(); /* turn echo back on */ > ioctl(0, TIOCLBIS, &pendin); /* set the pending input flag */ > } Undocumented? TTY(4) page 12 (66lines/page). This call does not exist on either System 5 or Version 7 - however the hack to put them into the kernel is about twenty lines. Oh for this and FIONREAD to be put into standard SYS V!!! Paul Guthrie.