More questions about how to issue a C-SHELL command within a C program

Peter da Silva peter at ficc.ferranti.com
Fri Aug 17 05:43:41 AEST 1990


In article <25285.26c9113d at kuhub.cc.ukans.edu>, jian at kuhub.cc.ukans.edu writes:
>         execlp("/bin/csh", "csh", "-c", "setenv TERM adm3a", (char *) 0);

You can't set your environment from a subshell. An environment is owned by
a process and inherited by its children, but never passed back. You need to
do something like print the commands on standard output, the way "tset" does:

47 % tset -s
set noglob;
setenv TERM at/386 console ;
setenv TERMCAP 'at386:am:bw:eo:xo:xt:bs:co#80:li#25:kn#4:ae=^P:al=\E[1L:cd=\E[0J:ce=\E[0K:cl=\E[2J\E[H:cm=\E[%i%2;%2H:ct=\E[3g:dc=\E[1P:dl=\E[1M:ho=\E[H:ic=\E[1@:K1=\EOp:K2=\EOq:K3=\EOr:K4=\EOs:K5=\EOt:K6=\EOu:K7=\EOv:K8=\EOw:K9=\EOx:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\EOT:k6=\EOU:k7=\EOV:k8=\EOW:k9=\EOX:kb=\b:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:nd=\E[C:se=\E[m:so=\E[7m:st=\EH:ue=\E[m:up=\E[A:us=\E[4m:ko=do,nd,up,ho';
unset noglob;
48 % grep tset .login
tset -s ... >/tmp/tset$$
source /tmp/tset$$
rm /tmp/tset$$
49 % 

This way the variables get set in the parent shell and so stick around after
the subshell or your C program (which is also a child of the shell) exits.

If you just want to set variables for programs you call, try "putenv".
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
peter at ferranti.com (currently not working)
peter at hackercorp.com



More information about the Comp.unix.questions mailing list