Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Passing vars to command

by Anonymous Monk
on Sep 30, 2002 at 21:07 UTC ( [id://201842]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Sorry to be a pain, but i have something that is probably simple for most of you, but a real pain for me.

I have the variables:
$password (contains password) $domain (contains domain name e.g bar.com) $username (contains users name) $fullname (contains something like billy bob, but needs to be passed as "billy bob")<br
and they need to be passed like this:
AddVirtUser tpasswd=$password $domain $username $fullname 500 0 0 0

(The 500 specifies user disk quota, and the 0 0 0 specifies whether the user can use telnet,ftp,smtp)

my current code looks like this:
if(system('/usr/local/bin/AddVirtUser' => 'tpasswd=$password', $domain, $username, $fullname, '500', '1 1 1', )){

Replies are listed 'Best First'.
Re: Passing vars to command
by trs80 (Priest) on Sep 30, 2002 at 21:18 UTC
    Your single quotes are making it send $password not the value of $password, try this instead.
    if(system('/usr/local/bin/AddVirtUser',"tpasswd=$password", $domain, $username, $fullname, '500', '1','1','1' )){
Re: Passing vars to command
by flounder99 (Friar) on Oct 01, 2002 at 11:31 UTC
    Other than the quoting problem on your password you might look at the last part. When using the list form of the system command there is a big difference between calling the external program using system "foo", "1 1 1" and system "foo", "1","1","1" let me give you and example:
    if (@ARGV) { print "called with "; foreach (@ARGV) { print "'$_' "; } print "\n"; } else { system ('perl', $0, "foo", "bar", "baz"); system ('perl', $0, "foo bar baz"); #single parameter system ("perl $0 foo bar baz"); system ("perl $0 'foo bar baz'"); } __OUTPUT___ $ perl temp.pl called with 'foo' 'bar' 'baz' called with 'foo bar baz' called with 'foo' 'bar' 'baz' called with 'foo bar baz'
    As you can see the first form calls the external program with three separate parameters 'foo', 'bar', 'baz'. The second form calls the program with one parameter "foo bar baz" These are very different and the external program may act completely different depending on what it expects.

    --

    flounder

Re: Passing vars to command
by Aristotle (Chancellor) on Sep 30, 2002 at 21:12 UTC
    And what's the question? Looks fine as it is..

    Makeshifts last the longest.

      it doesn't seem to be passing the password over.
        Now there's one. And duh at myself of course. You need to put the parameter in double quotes since single quotes don't interpolate variables: "tpasswd=$password". (Or maybe use the qq "operator", which allows to choose your own delimiters like in qq(tpasswd=$password).)

        Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://201842]
Approved by trs80
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-26 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found