diff --git a/lib/read.cs.js b/lib/read.cs.js index b454100..bc6f379 100644 --- a/lib/read.cs.js +++ b/lib/read.cs.js @@ -81,7 +81,7 @@ function writeTTY(text) { } catch (e) { WScript.StdErr.WriteLine('TTY Write Error: ' + e.number + '\n' + e.description + '\n' + PS_MSG); - WScript.Quit(1); + WScript.Quit(e.number || 1); } } @@ -92,7 +92,7 @@ function readByFSO() { } catch (e) { WScript.StdErr.WriteLine('TTY Read Error: ' + e.number + '\n' + e.description + '\n' + PS_MSG); - WScript.Quit(1); + WScript.Quit(e.number || 1); } return text; } @@ -111,7 +111,7 @@ function readByPW() { } catch (e) { WScript.StdErr.WriteLine('ScriptPW.Password Error: ' + e.number + '\n' + e.description + '\n' + PS_MSG); - WScript.Quit(1); + WScript.Quit(e.number || 1); } writeTTY('\n'); return text; diff --git a/lib/read.ps1 b/lib/read.ps1 index ea43e4b..3b80d8f 100644 --- a/lib/read.ps1 +++ b/lib/read.ps1 @@ -39,14 +39,11 @@ if ($options.encoded) { } [string] $inputTTY = '' -[bool] $isInputLine = $False +[string] $displaySave = $options.display +[bool] $silent = (-not $options.display) -and + $options.keyIn -and $options.noEchoBack -and (-not $options.mask) [bool] $isCooked = (-not $options.noEchoBack) -and (-not $options.keyIn) -function writeTTY ($text) { - execWithTTY ('Write-Host ''' + ($text -replace '''', '''''') + ''' -NoNewline') - $script:isInputLine = $True -} - # Instant method that opens TTY without CreateFile via P/Invoke in .NET Framework # **NOTE** Don't include special characters of DOS in $command when $getRes is True. # [string] $cmdPath = $Env:ComSpec @@ -54,20 +51,24 @@ function writeTTY ($text) { function execWithTTY ($command, $getRes = $False) { if ($getRes) { $res = (cmd.exe /C "CON powershell.exe -Command -" - if ($LastExitCode -ne 0) { exit 1 } + if ($LastExitCode -ne 0) { exit $LastExitCode } } } +function writeTTY ($text) { + execWithTTY ('Write-Host ''' + ($text -replace '''', '''''') + ''' -NoNewline') +} + if ($options.display -ne '') { writeTTY $options.display $options.display = '' } -if ($options.noEchoBack -and (-not $options.keyIn) -and ($options.mask -eq '*')) { +if ((-not $options.keyIn) -and $options.noEchoBack -and ($options.mask -eq '*')) { $inputTTY = execWithTTY ('$inputTTY = Read-Host -AsSecureString;' + '$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($inputTTY);' + '[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)') $True