sudo in php exec()

后端 未结 7 1239
执笔经年
执笔经年 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:38

    I had a similar situation trying to exec() a backend command and also getting no tty present and no askpass program specified in the web server error log. Original (bad) code:

    $output = array();
    $return_var = 0;
    exec('sudo my_command', $output, $return_var);
    

    A bash wrapper solved this issue, such as:

    $output = array();
    $return_var = 0;
    exec('sudo bash -c "my_command"', $output, $return_var);
    

    Not sure if this will work in every case. Also, be sure to apply the appropriate quoting/escaping rules on my_command portion.

提交回复
热议问题