http://www.perlmonks.org?node_id=1050006


in reply to Re: Need help in while entering password
in thread Need help in while entering password

Hi, Here is my code. Here I have hard coded my user name and password but password prompts. For $username1 = $password1, and $username2 = $password2. Here only $username2 = $password2 works. For $username1 = $password1 contains @ and it takes only the character before @ "Case" and it doesn't take entire password. I need you help to overcome this issue. Regards, Anand Mathan.

use strict; use warnings; my $username1 = "anand"; my $username2 = "girish"; my $password1 = "Case@123"; my $password2 = "Seat123#"; my $path = ("\"c:\\Program Files\\SecureFX\\sfxcl\""); my $server = "gaddwuat02"; @trans_file = ("/Q"." "."c:\\eqsys.txt"." "."sftp://$username:"."$pas +sword"."\@"."$server"); print "@trans_file\n"; my @trans = system("$path @trans_file");

Replies are listed 'Best First'.
Re^3: Need help in while entering password
by AnomalousMonk (Archbishop) on Aug 19, 2013 at 14:49 UTC
    Here is my code.

    The problem is that your code does not compile under strictures (the  use strict; statement; see strict). If  use strict; is left out and the code is run under warnings alone (the  use warnings; statement), Perl produces a bunch of warnings about uninitialized values and possible typos, warnings you should ponder well. Also take a look at the rules for interpolation discussed in the Quote and Quote-like Operators section of perlop; a careful Reading of this section of The Fine Manual would repay your effort. (Same as  perldoc perlop from the command line.)

    Here is an example of double-quote interpolation and single-quote non-interpolation. (These examples have been given before by others.) An example is also given of entering a string from the command line at a prompt. Note that once successfully entered, 'interpolating' characters do not interpolate further: Perl does not do multi-level or nested interpolation. Perhaps you can build on something like this example to demonstrate the problem(s) you are facing. (Note: I use  qq{double quotes} rather than  "double quotes" on my Windoze command line so that the code will not be cluttered by irruptions of backslashes.)

    >perl -wMstrict -le "my $def = 'hi there'; my @jkl = qw(foo bar); ;; my $str1 = qq{abc$def}; my $str2 = qq{ghi@jkl}; ;; print qq{str1: :$str1:}; print qq{str2: :$str2:}; ;; my $str3 = 'pqr$def'; my $str4 = 'xyz@jkl'; ;; print qq{str3: :$str3:}; print qq{str4: :$str4:}; ;; ;; print 'enter password: '; my $pw = <STDIN>; chomp $pw; ;; print qq{pw: :$pw:} " str1: :abchi there: str2: :ghifoo bar: str3: :pqr$def: str4: :xyz@jkl: enter password: open@sez$me pw: :open@sez$me:
      Thanks you all for your response. Actually the issue is with the tool I am using.. It picks the server where it found the @. It consider as a server after @. /Q c:\eqsys.txt sftp://v556837:Case@123@server1 In above case it picks 123 as hostname instead of server1. I don't have any issues if password not used special character like @, $, % in between. Regards, Anand Mathan.

        Hi, I need one more help on this to solve this issue. Now I have changed it as @trans_file = ("/Q"." "."c:\\eqsys.txt"." "."sftp://$username:"\@"."$server"); It asks for password in the screen and wait for user input to enter the password. like - Enter password :<Type password> and hit enter to move to next action. Is it possible to pass the password through script? Regards, Anand Mathan.

Re^3: Need help in while entering password
by Random_Walk (Prior) on Aug 20, 2013 at 14:34 UTC

    BTW in Perl, when referring to a file on the system to read, write, execute, etc, you can use the normal Unix like path separator even in Windows. Another trick, by using 'single' quotes to stop interpolation of string contents, you don't need to \\ escape your slashes

    # my $path = ("\"c:\\Program Files\\SecureFX\\sfxcl\""); my $notepad = 'c:/Windows/notepad.exe'; system $notepad, 'C:\Boot.ini';

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
Re^3: Need help in while entering password
by Anonymous Monk on Aug 19, 2013 at 10:35 UTC
    As the others said, you can't put @ or $ into dobule quotes. Just change it to my $password1 = 'Case@123';

      Thanks for reply. I have tried with single quote but it didn't help. One more thing I am running this script in windows environment'

        What does not work? What does your print "@trans_file\n"; line output? Does it look correct? Can you paste it into the command-prompt and run it? Does it work there? If it doesn't work, what's wrong with it?