The problem is in order to do it properly the environment variables DASP and DASU need to be set which are for an encrypted password and username respectively.
Passing passwords via environment is as insecure as via command line. But I guess that's nothing you can change. (Else, try passing the password via a file handle to an anonymous pipe.)
For setting environment variables for a child process, try something like this:
#!/usr/bin/perl use strict; use warnings; my $pid=fork(); defined($pid) or die "Can't fork: $!"; if ($pid) { # parent print "Parent waiting for the child ...\n"; waitpid($pid,0); print "Child has exited, exit code = $?\n"; } else { # child chdir('/tmp') or die "Can't chdir to /tmp: $!"; %ENV=(); # completely clear environment, for shorter demo output, +maybe also for security $ENV{'PATH'}='/bin:/usr/bin'; $ENV{'FOO'}='foo fofoo fofofooo'; $ENV{'BAR'}='bar bar barrrrrrrrrk'; exec($^X,'-e','print "* Hello from a new perl\n";print `pwd`;print + "* $_=$ENV{$_}\n" for sort keys %ENV; print "* bye\n"') or die "Can't execute $^X: $!"; # not reached }
Output:
>perl envchild.pl Parent waiting for the child ... * Hello from a new perl /tmp * BAR=bar bar barrrrrrrrrk * FOO=foo fofoo fofofooo * PATH=/bin:/usr/bin * bye Child has exited, exit code = 0 >
Alexander
In reply to Re: Set env variables as part of a command
by afoken
in thread Set env variables as part of a command
by devilock76
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |