pradeep,krishna has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks...

I am using the bellow script to execute an .exe file using runas command to run the application as different user

#perl system('runas /netonly /user:myserver.com\My_admin "ApplicationTest.ex +e D:\Pradeep"'); $pass='P@ssword01'; sleep(1); print "$pass\n";

I got the info on run as command via: http://technet.microsoft.com/en-us/library/cc771525.aspx
When I run the script the script is asking for the user password using the prompt,
The prompt is:Enter the password for myserver.com\My_admin:
I am using sleep to make my script wait for prompt and print statement to provide password to it.
I know printing to prompt is a stupid thing to do, but I don't know any other methods to do it.
Please assist me with the correct functions to send my inputs to the prompt.
Thanks in advance.

  • Comment on How to provide input to the password prompt in command prompt using script?
  • Download Code

Replies are listed 'Best First'.
Re: How to provide input to the password prompt in command prompt using script?
by Anonymous Monk on Apr 03, 2014 at 06:19 UTC

    I am using sleep to make my script wait for prompt and print statement to provide password to it.

    This can never work because system doesn't work like that

    You want to use IPC::Run3 or IPC::Open3, see perlipc for background info

Re: How to provide input to the password prompt in command prompt using script?
by Laurent_R (Canon) on Apr 03, 2014 at 07:13 UTC
    You lmight want to take a look at the Expect or Expect::Simple modules.
Re: How to provide input to the password prompt in command prompt using script?
by zentara (Cardinal) on Apr 03, 2014 at 10:38 UTC
    Oops, sorry, I misunderstood what you were trying to do

    This works well on Linux, I don't know if Term::ReadKey works on Winblows.

    #!/usr/bin/perl use strict; use Term::ReadKey; my $pwd = mask_pwd(); print "\n$pwd\n"; sub mask_pwd{ ReadMode(3); my $password = ''; print "Enter Password\n"; while(1){ my $ord = getord(); if ($ord == 10){last} # "Enter" if ($ord == 127) { # ie "Backspace" chop($password); print chr(8),' ',chr(8); next; } if($ord == 27){clearstream();$ord="\0"} if($ord != "\0"){ $password .= chr($ord); print '*'; } } ReadMode(0); return $password; } sub getord{ my $char; if (defined ($char = ReadKey(0))){} return ord($char); } sub clearstream{ while(1){ my $char; if (defined ($char = ReadKey(-1)) ){}else{return} } return ; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh