Check exit code
This commit is contained in:
parent
6dffd81b65
commit
b4bdf19667
2 changed files with 13 additions and 12 deletions
|
@ -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;
|
||||
|
|
19
lib/read.ps1
19
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 $command")
|
||||
if ($LastExitCode -ne 0) { exit 1 }
|
||||
if ($LastExitCode -ne 0) { exit $LastExitCode }
|
||||
return $res
|
||||
} else {
|
||||
$command | 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
|
||||
|
|
Loading…
Reference in a new issue