Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Congratulations, works for me :)

open my $source,'-|',"bash /tmp/wrapper.sh" or die "$!"; my $dump= do { local $/; <$source>}; my $VAR1; eval $dump; print $VAR1->{MONK}; #> jfroebe

lanx@nc10-ubuntu:/tmp$ cat wrapper.sh . /tmp/src.sh perl -MData::Dumper -e' print Dumper \%ENV' lanx@nc10-ubuntu:/tmp$ cat src.sh export MONK=jfroebe lanx@nc10-ubuntu:/tmp$

Thats an extremely stable approach, I can't think of a way to make it break! =)

you could even try to generate the code from wrapper.sh dynamically on the fly, hence avoiding any security/dependencies issues.

Cheers Rolf

( addicted to the Perl Programming Language)

UPDATE

> you could even try to generate the code from wrapper.sh dynamically on the fly

works! =)

my $bashcode=<<'_bash_'; . /tmp/src.sh; perl -MData::Dumper -e "print Dumper \%ENV"; _bash_ open my $source, '-|', qq{bash -c '$bashcode'} or die "$!"; my $dump= do { local $/; <$source>}; my $VAR1; eval $dump; print $VAR1->{MONK}; #> jfroebe

UPDATE

far less code, same result

my $bashcode=<<'__bash__'; . /tmp/src.sh; perl -MData::Dumper -e 'print Dumper \%ENV'; __bash__ my $VAR1; eval qx{bash -c "$bashcode"}; print $VAR1->{MONK}; #> jfroebe

In reply to Re^3: How to "source" a shell file in Perl? (Trojan Dump) by LanX
in thread How to "source" a shell file in Perl? by jfroebe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-25 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found