Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^19: Using STDIN after exec() with ActiveState Perl

by Anonymous Monk
on Jun 21, 2015 at 23:03 UTC ( [id://1131422]=note: print w/replies, xml ) Need Help??


in reply to Re^18: Using STDIN after exec() with ActiveState Perl
in thread Using STDIN after exec() with ActiveState Perl

output of perl -V: http://pastebin.com/6bE8L9vA

This is perlmonks, we don't need pastebins

Anyway, 5.20.1 is plenty new

Yeah, swig perl "%ENV" finds %ENV vs C's setenv which suggests Env::C - Get/Set/Unset Environment Variables on the C level

"plain xs" works for gettin %ENV changes reflected ; I never cared much for swig

#!/usr/bin/perl -- use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'modSV', CLEAN_AFTER_BUILD => 0; #include <stdlib.h> /* setenv/getenv */ char* modSV() { return getenv("HORSEY"); } END_C use Data::Dump qw/ dd /; dd( $ENV{HORSEY} => modSV() ); $ENV{HORSEY}='Neigh'; dd( $ENV{HORSEY} => modSV() ); __END__ (undef, undef) ("Neigh", "Neigh")

Replies are listed 'Best First'.
Re^20: Using STDIN after exec() with ActiveState Perl
by Yaribz (Beadle) on Jun 23, 2015 at 09:31 UTC

    "plain xs" works for gettin %ENV changes reflected ; I never cared much for swig
    Are you sure it's really related to xs vs swig and not Linux vs Windows? Did you test your code under Windows?
    Windows manages two sets of environment definitions as soon as the CRT is started which leads to consistency problems such as the one I encountered, but it's not specific to perl (cf http://www.codeproject.com/Articles/43029/When-what-you-set-is-not-what-you-get-SetEnvironme)

    For the record, here is the workaround I came up with for now:
    if($^O eq 'MSWin32') { require Win32::API; Win32::API->Import('msvcrt', 'int __cdecl _putenv (char* envstring)' +); } sub exportEnvVar { my $envVar=shift; my $envVarDef="$envVar=".($ENV{$envVar}//''); die "Unable to export environment variable definition \"$envVarDef\" +" unless(_putenv($envVarDef) == 0); }
    Then, when my script runs under Windows, I call exportEnvVar for each environment variable I update which needs to be seen by the dynamic library. This adds yet another platform-specific code to my script but I guess it's unavoidable... On Linux I don't need to do all that but on the other hand I need to restart (exec self) when I update LD_LIBRARY_PATH to select the dynamic library.
      Yes i tested on win32
        On my system with ActiveState perl your script crashes at startup (compilation runs fine, it crashes just after).
Re^20: Using STDIN after exec() with ActiveState Perl
by Yaribz (Beadle) on Jun 21, 2015 at 23:19 UTC
    Thanks for the links. I guess swig can deal with %ENV on linux but not on Windows then, since it works on my linux system without exec'ing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1131422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found