Page 1 of 1 1
Topic Options
#200072 - 2010-09-27 05:27 PM How to prevent character echo
StuR Offline
Fresh Scripter

Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
While I can prevent character echo with the REDIRECTOUTPUT command, as soon as I re-enable output, I get numeric character echo on the console.

Here's an example script:

;--------------------------------

$out = GETCHR("Enter password: ")
$out = GETCHR("Enter it again: ")
exit

Function GetChr($prompt)
? $prompt
REDIRECTOUTPUT("NUL")
GET $cmd
FLUSHKB
REDIRECTOUTPUT("")
EndFunction

;--------------------------

Regards,
Stuart.

Top
#200073 - 2010-09-27 05:59 PM Re: How to prevent character echo [Re: StuR]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Please see the following FAQ:

Why does the console display zeros and ones (amongst others)?
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81941#Post81941

Top
#200074 - 2010-09-27 07:51 PM Re: How to prevent character echo [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Welcome to KORG!

You're not catching the return codes, as Allen pointed out with the reference to the FAQ. You might want to use a UDF to gather the input so the password doesn't echo to the screen, such as:
 Code:
;;
;;======================================================================
;;
;;FUNCTION       GetStr()
;;
;;ACTION         returns a string, according to defined rules
;;
;;AUTHOR         Glenn Barnas
;;
;;VERSION        1.0 / 2001/11/14
;;
;;SYNTAX         GetStr(Count, [Secure],[Allowed])
;;
;;PARAMETERS     Count   - REQUIRED - specifies how many chars can be accepted
;;               Secure  - OPTIONAL - Char to display instead of the chars typed
;;               Allowed - Optional - a string defining which chars will be accepted.
;;
;;REMARKS        
;;
;;RETURNS        String
;;
;;DEPENDENCIES   none
;;
;;TESTED WITH    W2K, WXP, W2K3
;;
;;EXAMPLES       
;; 
Function GetStr($_Count, Optional $_Secure, OPTIONAL $_Allowed)

  Dim $_CC, $_SF, $_PC

  $_CC = 0			; character count
  $GetStr = ''			; init return string
  $_SF = 1			; string flag
  ; include backspace and return in string of allowed characters
  If $_Allowed <> ''
    $_Allowed = $_Allowed + Chr(8) + Chr(13)
  EndIf

  While $_SF			; loop until done
    Get $_PC			; get 1 character

    If $_Allowed <> ''		; If allowed string is defined
      If InStr($_Allowed, $_PC) = 0 ;And ($_PC <> Chr(13) or $_PC <> Chr(8))
        $_PC = ''		; char must be one of allowed
      EndIf
    EndIf

    Select
    Case $_PC = Chr(8)		; handle backspace
      Chr(8) + ' ' + Chr(8)	; erase character
      $_CC = $_CC - 1		; reduce count
      If $_CC > 0		; shorten or clear string
        $GetStr = Left($GetStr, $_CC)
      Else
        $GetStr = ''
      EndIf

    Case $_PC = Chr(13)		; handle Return
      $_SF = 0

    Case $_PC = ''		; handle non-allowed chars
      Beep

    Case 1			; got a char
      If $_Secure
        $_Secure			; print alt char if secure
      Else
        $_PC			; otherwise print the char
      EndIf
      $GetStr = $GetStr + $_PC	; add it to the string
      $_CC = $_CC + 1		; increment char count
    EndSelect

    ; Exit if character-count is reached
    If $_Count > 0 and $_CC = $_Count
      $_SF = 0
    EndIf

  Loop

  Exit 0

EndFunction
Using
 Code:
'  Enter password: '
$Pw1 = GetStr(99,'*')
@CRLF
'Confirm password: '
$Pw2 = GetStr(99,'*')
@CRLF
If $Pw1 <> $Pw2
  'Passwords do not match!' @CRLF
EndIf
Glenn

_________________________
Actually I am a Rocket Scientist! \:D

Top
#200075 - 2010-09-27 07:58 PM Re: How to prevent character echo [Re: Allen]
StuR Offline
Fresh Scripter

Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
Thanks Glenn. Finally hit me! I wasn't using the $x = Function() form of the command! Duh...

p.s. I started using Kix back in 1998 under WinNT 3.1 and recently started using it again this time under Win PE 3.0. Love the Kix2Exe tool too!

Regards

Stuart.


Edited by StuR (2010-09-27 08:22 PM)

Top
#200076 - 2010-09-27 08:23 PM Re: How to prevent character echo [Re: StuR]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Um, well - you AREN'T catching the return codes from the RedirectOutput() functions! (doh!) \:D

The first return code is actually redirected, so you are only seeing one of them. $RC = RedirectOutput() on both will fix this. If you were redirecting to a file and not NULL, you'd see that.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200077 - 2010-09-28 01:32 AM Re: How to prevent character echo [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: Glenn Barnas
If you were redirecting to a file and not NULL, you'd see that.

Glenn
Umm.... does not redirecting to NULL redirect to a file?

The OP redirects to NUL, not to NULL.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#200078 - 2010-09-28 03:13 AM Re: How to prevent character echo [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Well excuse my Unix roots and the extra "L".. the semantic is the same - he was redirecting to a "bit bucket" device. If he had redirected to a file, he would see the return code from the first RedirectOutput() there. He's seeing the second one on the screen because he's turned the redirection off before the RedirectOutput() return code is returned (and not caught). Jeez, I hope that's clear because I really don't want to return to this again. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200079 - 2010-09-28 03:21 AM Re: How to prevent character echo [Re: StuR]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
1998 - and it only took you 12 years to join us? \:\) Better late then never, I guess!

I'm just wrapping up a large PE 3.0 based deployment project that uses Kix scripts to prep the HD, deploy a WIM image (one if 2k3, two if 2k8/W7 for Sys and Boot), and then perform an automated system build after the installer answers a few questions about what role the server will play, the languages to install, hostname, IP settings, and such. The image, install tool, and several application packages and hotfixes that must be installed before network connection are all on the PE disk. Just one DVD to init, lay down the image, add/remove components, apply security policy, and install apps...

The PE 3.0 is a breeze to work with - I've really enjoyed working with it compared to Bart and other PE versions.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200081 - 2010-09-28 11:51 AM Re: How to prevent character echo [Re: Glenn Barnas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Windows PE? Windows Peasant Edition? I just googled it. Never heard of it till now. See, you can learn something new. \:\)
Top
#200100 - 2010-09-29 04:41 PM Re: How to prevent character echo [Re: Glenn Barnas]
StuR Offline
Fresh Scripter

Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
 Originally Posted By: Glenn Barnas
1998 - and it only took you 12 years to join us? \:\) Better late then never, I guess!

I'm just wrapping up a large PE 3.0 based deployment project that uses Kix scripts to prep the HD, deploy a WIM image (one if 2k3, two if 2k8/W7 for Sys and Boot), and then perform an automated system build after the installer answers a few questions about what role the server will play, the languages to install, hostname, IP settings, and such. The image, install tool, and several application packages and hotfixes that must be installed before network connection are all on the PE disk. Just one DVD to init, lay down the image, add/remove components, apply security policy, and install apps...

The PE 3.0 is a breeze to work with - I've really enjoyed working with it compared to Bart and other PE versions.

Glenn


HA - I don't remember Internet forums being around back then. Guess they were.

BTW, I think I found a coding error (gasp) in that nice character input function you referenced in this thread.

Here's the code fragment in question:

Case $_PC = Chr(8) ; handle backspace
Chr(8) + ' ' + Chr(8) ; erase character
$_CC = $_CC - 1 ; reduce count
If $_CC > 0 ; shorten or clear string
$GetStr = Left($GetStr, $_CC)
Else
$GetStr = ''
EndIf
---------
And here's my modification to prevent overwriting the prompt string with backspace characters when the string is empty:

Case $_PC = Chr(8) ; handle backspace
If $_CC > 0 ; shorten or clear string
$_CC = $_CC - 1 ; reduce count
$GetStr = Left($GetStr, $_CC)
Chr(8) + ' ' + Chr(8) ; erase character
Else
$GetStr = ''
EndIf

---------------

Regards,

Stuart.

Top
#200101 - 2010-09-29 04:45 PM Re: How to prevent character echo [Re: BradV]
StuR Offline
Fresh Scripter

Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
 Originally Posted By: BradV
Windows PE? Windows Peasant Edition? I just googled it. Never heard of it till now. See, you can learn something new. \:\)


Actually it's pretty cool. Basically a free, stripped-down version of Win 7 that you can use for many purposes. While it doesn't support Windows Explorer you can add your own standalone one (A43 for example). With this, you can use it as a repair environment, etc.

Top
#200102 - 2010-09-29 04:53 PM Re: How to prevent character echo [Re: StuR]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Wow - thanks! I wrote that back in 2001 or so and really rarely used it since.. just had it in the toolchest. I'll make the update.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200104 - 2010-09-29 05:26 PM Re: How to prevent character echo [Re: Glenn Barnas]
StuR Offline
Fresh Scripter

Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
 Originally Posted By: Glenn Barnas
Wow - thanks! I wrote that back in 2001 or so and really rarely used it since.. just had it in the toolchest. I'll make the update.

Glenn


It fit the bill perfectly for me as I needed a password function. Very nicely done.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 483 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.066 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org