Add comment in read.ps1

This commit is contained in:
anseki 2015-08-31 16:46:58 +09:00
parent c3b717b5b5
commit 904fa023c5

View file

@ -45,18 +45,18 @@ foreach ($arg in $argList) {
# **NOTE** Don't include special characters of DOS in $command when $getRes is True. # **NOTE** Don't include special characters of DOS in $command when $getRes is True.
# [string] $cmdPath = $Env:ComSpec # [string] $cmdPath = $Env:ComSpec
# [string] $psPath = 'powershell.exe' # [string] $psPath = 'powershell.exe'
function execWithTTY ($command, $getRes = $False, $errorThrow = $False) { function execWithTTY ($command, $getRes = $False, $throwError = $False) {
if ($getRes) { if ($getRes) {
$res = (cmd.exe /C "<CON powershell.exe -Command $command") $res = (cmd.exe /C "<CON powershell.exe -Command $command")
if ($LastExitCode -ne 0) { if ($LastExitCode -ne 0) {
if ($errorThrow) { throw $LastExitCode } if ($throwError) { throw $LastExitCode }
else { exit $LastExitCode } else { exit $LastExitCode }
} }
return $res return $res
} else { } else {
$command | cmd.exe /C ">CON powershell.exe -Command -" $command | cmd.exe /C ">CON powershell.exe -Command -"
if ($LastExitCode -ne 0) { if ($LastExitCode -ne 0) {
if ($errorThrow) { throw $LastExitCode } if ($throwError) { throw $LastExitCode }
else { exit $LastExitCode } else { exit $LastExitCode }
} }
} }
@ -73,6 +73,7 @@ if ($options.display) {
if ($options.displayOnly) { return "''" } if ($options.displayOnly) { return "''" }
if (-not $options.keyIn -and $options.hideEchoBack -and $options.mask -eq '*') { if (-not $options.keyIn -and $options.hideEchoBack -and $options.mask -eq '*') {
# It fails when it's not ready.
try { try {
$inputTTY = execWithTTY ('$text = Read-Host -AsSecureString;' + $inputTTY = execWithTTY ('$text = Read-Host -AsSecureString;' +
'$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($text);' + '$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($text);' +