sudo in php exec()

后端 未结 7 1238
执笔经年
执笔经年 2020-11-22 09:44

I don\'t know what the deal is here…

So I want to run an applescript: sudo osascript myscript.scpt

This works fine in the terminal, but not when

7条回答
  •  迷失自我
    2020-11-22 10:44

    I recently published a project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS The shell has a pty (pseudo terminal device, same as you would have in i.e. a ssh session), and you can get the shell as root if desired. Not sure you need root to execute your script, but given you mention sudo it is likely.

    After downloading you would simply use the following code:

    $shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
    $return1  = $shell->exeCmd('/path/to/osascript myscript.scpt');
    

提交回复
热议问题