.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.8k
stars
374
forks
source link
Read-Host returns 'Input request cancelled' when hitting Enter key without typing any input #3494
The following snippet in a Powershell Notebook cell reports an error if hitting the [Enter] key when prompted and does not behave as it would in a Powershell terminal (i.e. to return the value 'DEFAULT' without reporting an error):
$value = 'DEFAULT'
$value = if ($_ = Read-Host -Prompt "Enter value, or [Enter] to use default value - '$value'") {$_} else {$value}
$value
The error is
Read-Host:
Line |
2 | … = if ($_ = Read-Host -Prompt "Enter value, or [Enter] to use default …
| ~~~~~~~~~~~~~
| Input request cancelled
DEFAULT
The following snippet in a Powershell Notebook cell reports an error if hitting the [Enter] key when prompted and does not behave as it would in a Powershell terminal (i.e. to return the value 'DEFAULT' without reporting an error):
The error is
The code is as suggested in this answer on StackOverflow