Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: I need to export variable as another user

by aitap (Deacon)
on Aug 06, 2012 at 12:39 UTC ( #985694=note: print w/replies, xml ) Need Help??

in reply to I need to export variable as another user

You have been already told to use %ENV to work with these variables. Try something like this:

if (fork == 0) { # create a subprocess $ENV{myvariablename} = "desired variable value"; # set the variable ... exec("/path/to/program","some","program","arguments"); # run the program }

If you need to write shell commands, just run a shell and write your shell commands into it:

open my $shell, "|/bin/sh" || die "$!\n"; print $shell "export var=value\n"; ... print $shell "some complicated shell command # ;(){:|:&};:\n"; print $shell "/run/the/program --with-args\n";
Or use multi-line system(), for example, with here-doc:
system <<"END"; export var=value ... some() {shell commands} /run/some/program END

Sorry if my advice was wrong.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985694]
[LanX]: obscure facts: only naturally born monks can become president here!
[cbeckley]: I have a functioning module I use to spawn sets of commands across multiple servers.
[cbeckley]: It's nascent, and probably looks like baby Perl to the veterans.
[cbeckley]: I have several questions about it's future development. But it seems like a lot of code to put in a sopw.
[cbeckley]: Should I put the module and example calling code in cufp, and then ask questions in sopw?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-03-24 14:58 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (304 votes). Check out past polls.