왜 내 curl 명령은 applescript를 통해 실행할 때 실패하지만 터미널에서 직접 실행하면 제대로 작동합니까?

Aug 19 2020

내장 된 웹 인터페이스를 사용하여 설치된 프로젝터를 제어하는 ​​애플 스크립트를 작성하려고합니다. 적절한 URL을 핑 (ping)하고 필요에 따라 명령 줄에서 프로젝터를 제어 할 수있는 curl 명령이 있습니다.이 명령을 applescript로 빌드 할 때 (쇼 제어 소프트웨어에 필요함)

내 applescript는 현재 다음과 같습니다.

set theUrl to "http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on"
set theUsername to "dispadmin" -- set this to the username for the projector
set thePassword to "password" --set this to the password for the projector

set myFile to (POSIX path of (path to temporary items)) & "curl_downloaded_file.xml"

set curlScript to "/usr/bin/curl --connect-timeout 1 --anyauth --user" & " " & theUsername & ":" & thePassword & " -L " & theUrl & " -o " & myFile

display dialog "my variable: " & curlScript

do shell script curlScript

display dialog줄은 curl 명령이 어떻게 보이는지 디버깅하기위한 것입니다.이 명령을 실행하면 다음과 같은 결과가 나타납니다.

/usr/bin/curl --connect-timeout 1 --anyauth --user dispadmin:password -L http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on -o /private/var/folders/zs/f1hpkd2x281fvzyh4zd5dpcw0000gn/T/TemporaryItems/curl_downloaded_file.xml

맞는 것 같습니다. URL 주위에 따옴표를 추가하면 문제없이 터미널에서이 명령을 실행하여 원하는 효과를 얻을 수 있지만 Applescript는 계속해서 다음 오류를 표시합니다.

error "sh: -o: command not found
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   350  100   350    0     0  38888      0 --:--:-- --:--:-- --:--:-- 38888

100   267    0   267    0     0   5235      0 --:--:-- --:--:-- --:--:--  5235" number 127

이것은 curl이 실행되는 것처럼 보이지만 제어를 트리거하기 위해 프로젝터의 웹 서버에 충돌하지 않으며 error "sh: -o: command not found명령이 올바르게 구문 분석 / 전달되지 않는다고 생각하게 만듭니다.

내가 여기서 뭘 잘못하고 있니?

답변

2 user3439894 Aug 19 2020 at 22:00

동안

http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on

브라우저 에서는 잘 작동 하지만 에서는 작동하지 않습니다 .

문제를 해결하려면 URL 을 인용해야합니다 .

에서 set curlScript to ...변화 theUrl중 하나에 theUrl's quoted form또는 :quoted form of theUrl