about_PSConsoleHostReadLine
업데이트 날짜: 2014년 5월
적용 대상: Windows PowerShell 4.0, Windows PowerShell 5.0
항목
about_PSConsoleHostReadLine
간단한 설명
Windows PowerShell이 콘솔 프롬프트에서 입력을 읽는 방법을 사용자 지정하는 방법에 대해 설명합니다.
자세한 설명
Windows PowerShell V3부터는 콘솔 입력이 처리되는 기본 방법을 재정의하는 PSConsoleHostReadLine이라는 함수를 작성할 수 있습니다.
예제
다음 예제에서는 메모장을 시작하고 사용자가 만드는 텍스트 파일에서 입력을 가져옵니다.
function PSConsoleHostReadLine
{
$inputFile = Join-Path $env:TEMP PSConsoleHostReadLine
Set-Content $inputFile "PS > "
## Notepad opens. Enter your command in it, save the file,
## and then exit.
notepad $inputFile | Out-Null
$userInput = Get-Content $inputFile
$resultingCommand = $userInput.Replace("PS >", "")
$resultingCommand
}
설명
기본적으로 Windows PowerShell은 Windows 콘솔 하위 시스템에서 모든 키 누름, F7 메뉴 및 기타 입력을 처리하는 "가공 모드"라는 콘솔에서 입력을 읽습니다. Enter 키나 Tab 키를 누르면 Windows PowerShell은 해당 지점까지 입력한 텍스트를 가져옵니다. Enter 키나 Tab 키를 누르기 전에 Ctrl+R, Ctrl+A, Ctrl+E 또는 다른 키를 눌렀는지는 알 수 없습니다. Windows PowerShell 버전 3에서는 PSConsoleHostReadLine 함수를 통해 이 문제가 해결됩니다. Windows PowerShell 콘솔 호스트에서 PSConsoleHostReadline이라는 함수를 정의하면 Windows PowerShell에서 "가공 모드" 입력 메커니즘 대신 해당 함수를 호출합니다.
참고 항목
about_Prompts