从python文件调用PHP脚本会出现错误/bin/sh:path:权限被拒绝

2024-04-26 20:59:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从python内部在终端中运行PHP脚本,但似乎无法访问PHP文件

我调用PHP脚本的python代码是:

import subprocess
proc = subprocess.Popen("/Users/cedrique/documents/test.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

但是,这给了我一个权限被拒绝的错误:

/bin/sh: /Users/cedrique/documents/test.php: Permission denied

我能给它正确的权利吗?或者我得把它放在另一个文件夹里

谢谢你


Tags: 文件代码testimport脚本终端stdoutproc
1条回答
网友
1楼 · 发布于 2024-04-26 20:59:38

您需要以脚本名作为参数运行php

proc = subprocess.Popen(["php", "/Users/cedrique/documents/test.php"], stdout=subprocess.PIPE)

这里也不需要shell=True,因为您没有使用任何shell操作

相关问题 更多 >