2016-12-12 5 views
1

그래서 나는 하루 종일 머리카락을 찢어 냈습니다. Cloudflare에서 로그를 가져 오는 Windows 컴퓨터에서 작업하는 컬 명령이 있습니다.명령은 cmd 프롬프트에서 작동하지만 Powershell에서는 작동하지 않습니다. 무엇을 잘못하고 있습니까?

curl -sv -o logname.log.gz -X GET -H "Accept-encoding: gzip" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: 12345" "https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709" 

나는했습니다, 파워 쉘에서 실행하지만 단순히 명령을 얻을 수없는, 현재 시간에 따라 다른 시작 및 종료 시간 매개 변수를 만들기의 최종 목표로 PowerShell은이 점을 가져하려고 해요 가장 최근의 가장 단순한 다양한 트랙을 시도했습니다. 나에게 고정에이 이미 내 유닉스 타임 스탬프가 조금 꺼져 있는지 알고

{ [11971 bytes data] 
* Failed writing body (0 != 11963) 
* Failed writing data 
* Curl_http_done: called premature == 1 
* Closing connection 0 
* schannel: shutting down SSL/TLS connection with api.cloudflare.com port 443 
* schannel: clear security context handle 

오류 및 계획을 제공

cmd.exe /c 'curl -sv -o logname.log.gz -X GET -H "Accept-encoding: gzip" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: 12345" "https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709"' 

그 다음하지만 내가 이해할 수없는 것은 같은 명령은 명령을 통해 작동하는 이유 Powershell을 통하지 않고 프롬프트합니다.

누군가 도움을 줄 수 있습니까?

당신이 인용하고 모두 특수 문자, 때로는 중첩을 처리해야하기 때문에 지뢰밭이 될 수 PowerShell의 기본 명령에 매개 변수를 다루는 당신에게

+0

'cmd/C '...'와 같이 'cmd'는 큰 따옴표만을 지원하기 때문에 'cmd/C'에 대해 작은 따옴표를 사용할 수 없습니다. – aschipfl

답변

1

감사드립니다.

그것은 PowerShell에서 Start-Process를 사용하고에게 매개 변수의 배열을 제공하는 아마 더 안전 :

Start-Process curl.exe -ArgumentList '-sv','-o','logname.log.gz','-X','GET','-H','Accept-encoding: gzip','-H','X-Auth-Email:','[email protected]','-H','X-Auth-Key:','12345','https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709' 

하지만 당신이 정말해야을, 궁극적으로 훨씬 쉽게 될 것입니다 Invoke-WebRequest을 확인합니다.

$body = @{ 
    start = 1481509909 
    end = 1481538709 
} 

$headers = @{ 
    'Accept-Encoding' = 'gzip' 
    'X-Auth-Email' = '[email protected]' 
    'X-Auth-Key' = '12345' 
} 

$response = Invoke-WebRequest -Uri 'https://api.cloudflare.com/client/v4/zones/987654/logs/requests' -OutFile logname.log.gz -Body $body -Headers $headers 

참고 : 이것은 전혀 테스트되지는 않았지만 좋은 출발점이되어야합니다.

+0

고마워요! 이것은 많은 도움이되었으므로 이제 위의 방법을 사용하여 요청을 실행할 수 있습니다. 그러나 log.gz 파일에 액세스 할 때 아카이브가 알 수없는 형식이거나 손상되었음을 알려줍니다. $ 바디 = @ { 시작 = 1,481,509,909 끝 = 1,481,538,709 } $ 헤더 = @ { '동의 인코딩'= 'gzip으로' '의 X-인증 - 이메일'= '[email protected]' 'X-Auth-Key'= '12345' } $ 응답 = Invoke-WebRequest -Uri 'https://api.cloudflare.com/client/v4/zones/98765/logs/requests'-OutFile C : \ logname.log.gz -Headers $ headers -Body $ body -ContentType "application/json" 아이디어가 있으십니까? – cjohnson

관련 문제