it-source

파워셸을 통해 컬을 실행합니다 - 인수를 구성하는 방법은 무엇입니까?

criticalcode 2023. 8. 24. 22:12
반응형

파워셸을 통해 컬을 실행합니다 - 인수를 구성하는 방법은 무엇입니까?

스크립트에 파일을 업로드하기 위해 curl을 실행하려고 하는데, 문자열 조작 등을 해야 하기 때문에 배치를 사용하는 것이 고통스러워서 powershell로 전환했습니다.

하지만 컬을 실행할 파워셸을 얻을 수 없는 것 같습니다.

$hash = "test"
$fileToUpload = "hello world.txt"
$user = "user"
$password = "passy"
curl --ftp-create-dirs -T $fileToUpload -u ${user}:${pass} ftp://example.com/$hash/$fileToUpload

그 결과:

Invoke-WebRequest : Parameter cannot be processed because the parameter name 'T' is ambiguous. Possible matches include: 
-TimeoutSec -TransferEncoding.
At line:5 char:24
+ curl --ftp-create-dirs -T $fileToUpload -u ${user}:${pass} ftp://example.com/$ha ...
+                        ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Curl.exe가 내 PATH에 있습니다.

PowerShell에서curl에 대한 기본 별칭입니다.Invoke-WebRequestcmdlet.별칭은 명령 확인에 우선합니다.문제를 해결하려면 다음을 사용합니다.curl.exe대신에curl명령이 별칭으로 확인되지 않았습니다.또는 별칭을 제거할 수 있습니다.Remove-Item alias:curl그러나 별칭에 내장되어 있으므로 이 명령을 프로필에 넣거나 모든 세션에서 호출해야 합니다.

PowerShell이 명령을 확인하는 방법을 잘 모르면 다음을 사용할 수 있습니다.Get-Commandcmdlet:

Get-Command curl
Get-Command curl.exe

언급URL : https://stackoverflow.com/questions/30807318/running-curl-via-powershell-how-to-construct-arguments

반응형