Windows PowerShell에서 입력 요청 및 수락

Windows PowerShell에서 입력 요청 및 수락

퀴즈 스크립트에서 초보자를 위한 프로그래밍의 Seinfeld 퀴즈 게임과 같이 빈칸 채우기 질문과 답을 어떻게 입력하시겠습니까?

답변1

게다가Read-Host당신은 직접 사용할 수 있습니다System.Console클래스, 단일 문자를 읽으려면(ENTER가 필요 없음):

$key = [Console]::ReadKey()
$char = $key.KeyChar

답변2

거기에는읽기 호스트 cmdlet사용자의 입력을 읽으려면 몇 가지가 필요합니다.조건부 논리정답을 확인합니다.

답변3

#Ask the player the seventh question
while (($question7 -eq "")) {

  Clear-Host  #Clear the Windows command console screen

  Write-Host
  Write-Host " What food item did Jerry say Newman wouldn't eat even if it was deep fried in chocolate sauce?"
  Write-Host
  Write-Host " Broccoli"
  Write-Host " Peas"
  Write-Host " Apples"
  Write-Host " Carrots"
  Write-Host
  $question7 = Read-Host " Type the word representing the correct answer" `
    "and press the Enter key"

}

관련 정보