使用Python运行chgrp和chown命令时,从PHP调用脚本时无法正常工作的文件

2024-04-26 03:26:41 发布

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

我的php表单应用程序在提交时将获取表单数据并调用python脚本。这个python脚本包含创建文件、更改其权限、更改组和所有者的代码。最后,它需要将文件移动到本地文件系统上的另一个位置。在

问题:当权限变化良好(即chmod有效)时,组和所有者不变(chgrp和chown不工作)。在

这是python代码

target = open(filename, "a")
someTextToWrite = "foobar"
target.write(someTextToWrite)
target.close()
src = os.path.dirname(os.path.realpath(__file__))
fullpath = src +"/" + filename
subprocess.call(["chmod","777",fullpath])
subprocess.call(["chown","root",fullpath])
subprocess.call(["chgrp","root",fullpath])
shutil.move(fullpath, dest)

另外,如果我在终端上直接运行同一段代码而不做任何修改,那么这三个代码:chmod、chown和chgrp都可以正常工作。我看到其他人有一个similar issue,但没有提供解决方案。在

谢谢你的帮助。在


Tags: 文件代码src脚本权限表单targetcall