From b4bdf19667e0ced3182fbc3155fcd9293340f59d Mon Sep 17 00:00:00 2001 From: anseki Date: Wed, 1 Apr 2015 19:36:00 +0900 Subject: [PATCH] Check exit code --- lib/read.cs.js | 6 +++--- lib/read.ps1 | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) 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