PowerShell에서 exe 파일을 실행하는 방법

PowerShell에서 exe 파일을 실행하는 방법

Windows 운영 체제는 자동화에 매우 유용할 수 있는 여러 명령줄 도구를 지원합니다.

curl은 HTTP, HTTPS, FTP, FTPS, SMTP 등과 같은 지원되는 프로토콜을 통해 서버에 요청을 보내거나 서버로부터 요청을 받을 수 있는 이러한 유용한 도구 중 하나입니다…

이 명령줄 도구는 FTP 업로드, 프록시 지원, 전송 재개 및 제한된 대역폭과 같은 추가 기능을 지원합니다.

Windows 공식 빌드 1804부터 curl이 도구 체인에 추가되었습니다. 이를 확인하려면 Windows 명령 프롬프트를 열고 다음 명령을 실행하면 됩니다.

curl --version

출력:

curl 7.55.1 (windows)

출력은 curl 설치에 따라 변경될 수 있습니다.

Windows PowerShell에서의 curl

Windows PowerShell에서는 Windows 명령 프롬프트와 약간 다른 방식으로 curl 명령을 사용해야 합니다. curl 명령은 Invoke-WebRequest cmdlet에 대한 별칭으로 매핑되어 있기 때문입니다. PowerShell 창에서 다음 명령을 실행하여 이를 확인할 수 있습니다.

Get-Alias -Name curl

출력:

CommandType		Name						Version		Source
-----------		----						-------		------
Alias			curl -> Invoke-WebRequest

이 모든 명령은 PowerShell 명령 실행 과정에서 해결됩니다. 일반적으로 별칭은 가장 높은 우선 순위를 가집니다. 따라서 PowerShell에서는 curl 대신 curl.exe 실행 파일을 직접 사용하는 것이 좋습니다. Get-Command cmdlet을 사용하여 실행 시간에 이 두 명령이 어떻게 해결되는지 볼 수 있습니다.

Get-Command curl

출력:

CommandType		Name						Version		Source
-----------		----						-------		------
Alias			curl -> Invoke-WebRequest
Get-Command curl.exe

출력:

CommandType		Name						Version		Source
-----------		----						-------		------
Application		curl.exe					7.55.1.0	C:\Windows\system32\curl.exe

결론은 Windows 명령 프롬프트와 동일하게 PowerShell에서 curl을 사용해야 하는 경우 curl 실행 파일(curl.exe)을 직접 호출해야 한다는 것입니다. 그렇지 않으면 Invoke-WebRequest cmdlet으로 해결되는 PowerShell curl 별칭을 사용해야 합니다.

PowerShell의 curl 구문

curl.exe [options] <url>

curl 명령 및 -a, -C와 같은 옵션에 대한 추가 정보를 얻으려면 다음 명령을 실행할 수 있습니다.

curl.exe --help

출력:

Usage: curl [options...] <url>

-a, --append		Append to target file when uploading
.
.
.
-C, --continue-at	<offset> Resumed transfer offest

예시 시나리오

응답으로 반환되는 HTML 웹 페이지를 표시합니다.

curl.exe https://www.google.com

응답, 요청 헤더 및 응답 헤더를 표시합니다.

curl.exe -v https://www.google.com

헤더 정보를 표시합니다.

curl.exe -I https://www.google.com

헤더 정보를 file1.txt라는 파일에 저장합니다.

curl.exe -I https://www.google.com -o file1.txt
튜토리얼이 마음에 드시나요? DelftStack을 구독하세요 YouTube에서 저희가 더 많은 고품질 비디오 가이드를 제작할 수 있도록 지원해주세요. 구독하다
Migel Hewage Nimesha avatar Migel Hewage Nimesha avatar

Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.