in reply to YES you can! Re: setenv in perl
in thread setenv in perl

I was trying to follow your post as I think triangulating this question with C makes complete sense. Have I missed a step?

$ touch 1.bliako.pl $ chmod +x 1.bliako.pl $ gedit 1.bliako.pl &

I paste in your code and set it to execute. First I need Inline.pm:

$ ./1.bliako.pl Can't locate Inline.pm in @INC (you may need to install the Inline mod +ule) ... BEGIN failed--compilation aborted at ./1.bliako.pl line 13. $ sudo cpan ... cpan[1]> install Inline Reading '/home/bob/.cpan/Metadata' Database was generated on Tue, 29 May 2018 20:29:03 GMT Fetching with LWP: http://www.cpan.org/authors/01mailrc.txt.gz Reading '/home/bob/.cpan/sources/authors/01mailrc.txt.gz' ...................................................................... +......DONE ... Installing /usr/local/share/perl/5.22.1/Inline/Foo.pm ... /usr/bin/make install -- OK cpan[2]> q Terminal does not support GetHistory. Lockfile removed. ^[^C $ ./1.bliako.pl Error. You have specified 'C' as an Inline programming language. I currently only know about the following languages: Foo, foo If you have installed a support module for this language, try deleting + the config-x86_64-linux-gnu-thread-multi-5.022001 file from the following +Inline DIRECTORY, and run again: /home/bob/1.scripts/_Inline (And if that works, please file a bug report.)

What am I missing?

$ cat 1.bliako.pl #!/usr/bin/perl # setenv from within perl to effect parent shell # actually parent should be more appropriately # called "adopted" or "step-parent", re execl # there is one little requirement: # you should run this program via shell's exec: # % exec <scriptname> # # author: bliako # date: 09/07/2018 use Inline C => DATA; # ... # this should be the last statement in your script # because nothing else will be executed after that # not even the 'or die ...' mysetenv("test", "TURE") or die "mysetenv() failed"; __END__ __C__ #include <stdio.h> #include <unistd.h> #include <stdlib.h> int mysetenv(const char *K, const char *V){ if( K==NULL || V==NULL ){ return 0; } char *shell = getenv("SHELL"); if( setenv(K, V, 1) ){ fprintf(stderr, "mysetenv() : call to setenv() has fai +led.\n"); return 1; } // replace caller shell with a new shell which now has // set this new env var //printf("shell to exec is %s\n", shell); execl(shell, NULL, NULL); perror("execl failed, "); return 1; } $

Replies are listed 'Best First'.
Re^2: YES you can! Re: setenv in perl
by bliako (Abbot) on Jul 12, 2018 at 12:10 UTC