How to use sudo inside of a Run Script build phase in Xcode 4?

后端 未结 7 1898
梦谈多话
梦谈多话 2021-02-02 14:47

I need use execute a command inside of a script in a Run Script build phase in Xcode 4 using sudo. However, the compiler complains:

sudo: no tty present a

相关标签:
7条回答
  • 2021-02-02 15:07

    You can either run commands directly as a administrator with the following (changing echo YourCommandHere > /tmp/hello to your command):

    osascript -e 'do shell script "sudo echo YourCommandHere > /tmp/hello " with administrator privileges'
    

    Or run a script in your source directory using:

    osascript -e 'do shell script "bash -x $SOURCE_ROOT/MyAdminScript.sh 1>/tmp/build-log 2>/tmp/build-log.err" with administrator privileges'
    

    This runs the script and logs it output to /tmp/build-log and /tmp/build-log.err

    For useful variables in the script see https://help.apple.com/xcode/mac/8.0/#/itcaec37c2a6

    0 讨论(0)
提交回复
热议问题