Windows PowerShell에서 출력 작성 방법

  1. PowerShell의 Write-Output Cmdlet
  2. PowerShell의 Write-Host Cmdlet
  3. PowerShell의 Write-Debug Cmdlet
  4. PowerShell의 Write-Verbose Cmdlet
Windows PowerShell에서 출력 작성 방법

콘솔에 출력을 쓰는 것은 사용자에게 정확한 피드백을 제공하는 모든 언어에서 필수적인 과정입니다. 그러나 Windows PowerShell에서는 출력을 인쇄하는 여러 가지 방법이 있습니다. 이 문서에서는 다양한 Write cmdlet을 구분하고 언제, 어디서 사용할 수 있는지에 대한 상황을 제공할 것입니다.

cmdlet에 대한 논의에 들어가기 전에, Windows PowerShell에서는 두 개의 따옴표("")로 하나의 줄을 감싸서 무언가를 출력할 수 있다는 점은 주목할 가치가 있습니다.

예제 코드:

"Hello World!"

출력:

Hello World!

이 구문은 문자열 리터럴 표현식 및 숨겨진 파이프라인 때문에 Windows PowerShell에서 가능합니다. 이 구문은 아래의 예제 코드와 같습니다.

예제 코드:

"Hello World!" | Out-Host

반면에, Out-Host cmdlet은 표시를 위해 전송된 객체를 보냅니다.

PowerShell의 Write-Output Cmdlet

Windows PowerShell에서 첫 번째 인쇄 방법은 Write-Output cmdlet입니다. 이 cmdlet은 PowerShell 스크립팅 환경 내에서 인쇄하는 기본 구문입니다. 우리는 이것을 여러 언어의 기본 인쇄 명령인 print, 및 stdout에 비유할 수 있습니다.

예제 코드:

Write-Output "Hello World!"

출력:

Hello World!

PowerShell의 Write-Host Cmdlet

Write-Host cmdlet은 이전 방법인 Write-Output과 유사한 또 다른 인쇄 방법입니다. 유일한 차이점은 -BackgroundColor-ForegroundColor 매개변수를 사용하여 다양한 색상을 출력할 수 있다는 것입니다.

PowerShell의 Write-Debug Cmdlet

Write-Debug cmdlet은 Windows PowerShell에서 출력하는 또 다른 방법입니다. 그러나 이는 일반적으로 스크립팅 환경에서 디버그 메시지를 인쇄하는 데 더 많이 사용됩니다. 메시지는 기본적으로 표시되지 않지만 $debugPreference 변수를 사용하여 표시할 수 있습니다.

예제 코드:

Write-Debug "Error on line 1 but will silently continue."
$debugPreference = "Continue"
Write-Debug "Error on line 3 will now be displayed"

출력:

DEBUG: Error on line 3 will now be displayed 

PowerShell의 Write-Verbose Cmdlet

Write-Verbose cmdlet은 Windows PowerShell의 자세한 메시지 스트림에 텍스트를 씁니다. 자세한 메시지 스트림은 명령 프로세스에 대한 더 많은 정보를 전달하도록 정의됩니다. Write-Debug와 마찬가지로, 자세한 메시지는 기본적으로 표시되지 않지만 $VerbosePreference 변수를 사용하거나 스위치 매개변수 -Verbose를 추가하여 표시할 수 있습니다.

예제 코드:

Write-Verbose -Message "This will not be displayed."
Write-Verbose -Message "This will be displayed" -Verbose

출력:

VERBOSE: This will be displayed
튜토리얼이 마음에 드시나요? DelftStack을 구독하세요 YouTube에서 저희가 더 많은 고품질 비디오 가이드를 제작할 수 있도록 지원해주세요. 구독하다
Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn