须藤在php exec() [英] sudo in php exec()

查看:49
本文介绍了须藤在php exec()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是什么交易...

I don't know what the deal is here…

所以我想运行一个applescript:sudo osascript myscript.scpt

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

这在终端中很好用,但是当我通过PHP的exec()执行它时却不能.什么都没发生.控制台显示

This works fine in the terminal, but not when I execute it via PHP's exec(); nothing happens. The console says

no tty present and no askpass program specified ; TTY=unknown ; …

我做了研究,看来我缺少sudo命令的密码.我尝试了几种不同的方法来解决此问题,包括:

I did my research, and it seems I'm missing the password for the sudo command. I tried a couple different ways to get around this, including:

  • /etc/sudoers
  • 中编写%admin ALL=(ALL) ALL
  • proc_open()而不是exec()
  • writing %admin ALL=(ALL) ALL in /etc/sudoers
  • and proc_open() instead of exec()

似乎没有一个起作用,因此驱使我疯狂!

none of which seem to be working, consequently driving me CrAzY!

所以基本上,有没有一种明确的方法可以使PHP执行简单的终端命令?

So basically, is there a clear-cut way to get PHP to execute a simple terminal command?

澄清一下,myscript.scpt是一个简单的appleScript,它更改了屏幕UI(用于较大的项目).从理论上讲,只需osascript myscript.scpt就足够了,但是出于某些原因,sudo是从系统中调用 some 响应所必需的.如果sudo可以通过某种方式消除,我认为我不会遇到这种权限问题.

to clarify, myscript.scpt is a simple appleScript that changes the onscreen UI (for a larger project). In theory, simply osascript myscript.scpt should be enough, however the sudo is for some reason necessary to invoke some response from the system. If the sudo could be somehow eliminated, I don't think I would be having this permissions problem.

推荐答案

听起来您需要设置无密码sudo.试试:

It sounds like you need to set up passwordless sudo. Try:

%admin ALL=(ALL) NOPASSWD: osascript myscript.scpt

还注释掉以下行(通过visudo在/etc/sudoers中):

Also comment out the following line (in /etc/sudoers via visudo), if it is there:

Defaults    requiretty

这篇关于须藤在php exec()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆