子进程. popen需要哪些权限?

时间:2022-11-03 14:51:27

The following code:

下面的代码:

gb = self.request.form['groupby']
typ = self.request.form['type']
tbl = self.request.form['table']

primary = self.request.form.get('primary', None)

if primary is not None:
    create = False
else:
create = True

mdb = tempfile.NamedTemporaryFile()
mdb.write(self.request.form['mdb'].read())
mdb.seek(0)

csv = tempfile.TemporaryFile()
conversion = subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,),stdout=csv)

Causes the this error when calling the last line i.e. 'conversion =' in OS X.

在调用最后一行时导致这个错误。在OS X中“转换=”。

Traceback (innermost last):
  Module ZPublisher.Publish, line 119, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 42, in call_object
  Module circulartriangle.mdbtoat.mdb, line 62, in __call__
  Module subprocess, line 543, in __init__
  Module subprocess, line 975, in _execute_child
OSError: [Errno 13] Permission denied

I've tried chmod 777 /Users/jondoe/development/mdb-export - what else might be required?

我尝试过chmod 777 /Users/jondoe/development/mdb-export——还需要什么?

4 个解决方案

#1


11  

Assuming that permissions on parent folders are correct (i.e. all parent folders should have +x permission), try adding:

假设父文件夹的权限是正确的(即所有父文件夹都应该有+x权限),请尝试添加:

shell=True

to the Popen command such as:

至Popen命令,例如:

subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,), stdout=csv, shell=True)

#2


7  

It seems the 'Permissions denied error' was orginally coming from Popen trying to execute mdb-export from the wrong location (and to compound things, with the wrong permissions).

“权限被拒绝错误”似乎是来自Popen试图从错误的位置执行mdb-export(并使用错误的权限来复合内容)。

If mdbtools is installed, the following works fine and inherits the correct permissions without the need for sudo etc.

如果安装了mdbtools,则可以很好地继承正确的权限,而不需要sudo等。

subprocess.Popen(("mdb-export", mdb.name, tbl,),stdout=csv)

(Worth noting, I got myself into a muddle for a while, having forgotten that Popen is for opening executables, not folders or non-exectable files in folders)

(值得注意的是,我一时陷入了混乱,忘记了Popen是用来打开可执行文件的,而不是文件夹或非执行文件)

Thanks for all your responses, they all made for interesting reading regardless :)

谢谢你的回复,不管怎样,它们都是有趣的读物。

#3


1  

Can you feed "sudo" to subprocess? See this SO thread.

你能将“sudo”输入子进程吗?看到这个线程。

@Jon Hadley, from the interpreter:

@Jon Hadley,翻译:

>>> import subprocess
>>> p = subprocess.call(['sudo','/usr/bin/env'])
PASSWORD:
[snip]

USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=telliott99
SUDO_UID=501
SUDO_GID=20

From Terminal on OS X, I have to do sudo when I run the script:

从OS X上的终端开始,运行脚本时需要做sudo:

$ sudo python test.py

then this (in test.py) gives the same output as before:

然后这个(在test.py中)给出的输出与之前相同:

import subprocess
p = subprocess.Popen('/usr/bin/env')

Getting subprocess to directly handle the authentication from a script is probably not a good idea, since it hides the privilege escalation. But you could look at pexpect and this SO answer.

让子进程直接从脚本处理身份验证可能不是一个好主意,因为它隐藏了特权升级。但是你可以看看pexpect和这个SO答案。

#4


0  

You also need to ensure read and execute permissions for the user running that code on the directories up the chain - /Users, /Users/jondoe and /Users/jondoe/development.

您还需要确保在链上的目录上运行该代码的用户的读取和执行权限—/Users、/Users/jondoe和/Users/jondoe/development。

#1


11  

Assuming that permissions on parent folders are correct (i.e. all parent folders should have +x permission), try adding:

假设父文件夹的权限是正确的(即所有父文件夹都应该有+x权限),请尝试添加:

shell=True

to the Popen command such as:

至Popen命令,例如:

subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,), stdout=csv, shell=True)

#2


7  

It seems the 'Permissions denied error' was orginally coming from Popen trying to execute mdb-export from the wrong location (and to compound things, with the wrong permissions).

“权限被拒绝错误”似乎是来自Popen试图从错误的位置执行mdb-export(并使用错误的权限来复合内容)。

If mdbtools is installed, the following works fine and inherits the correct permissions without the need for sudo etc.

如果安装了mdbtools,则可以很好地继承正确的权限,而不需要sudo等。

subprocess.Popen(("mdb-export", mdb.name, tbl,),stdout=csv)

(Worth noting, I got myself into a muddle for a while, having forgotten that Popen is for opening executables, not folders or non-exectable files in folders)

(值得注意的是,我一时陷入了混乱,忘记了Popen是用来打开可执行文件的,而不是文件夹或非执行文件)

Thanks for all your responses, they all made for interesting reading regardless :)

谢谢你的回复,不管怎样,它们都是有趣的读物。

#3


1  

Can you feed "sudo" to subprocess? See this SO thread.

你能将“sudo”输入子进程吗?看到这个线程。

@Jon Hadley, from the interpreter:

@Jon Hadley,翻译:

>>> import subprocess
>>> p = subprocess.call(['sudo','/usr/bin/env'])
PASSWORD:
[snip]

USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=telliott99
SUDO_UID=501
SUDO_GID=20

From Terminal on OS X, I have to do sudo when I run the script:

从OS X上的终端开始,运行脚本时需要做sudo:

$ sudo python test.py

then this (in test.py) gives the same output as before:

然后这个(在test.py中)给出的输出与之前相同:

import subprocess
p = subprocess.Popen('/usr/bin/env')

Getting subprocess to directly handle the authentication from a script is probably not a good idea, since it hides the privilege escalation. But you could look at pexpect and this SO answer.

让子进程直接从脚本处理身份验证可能不是一个好主意,因为它隐藏了特权升级。但是你可以看看pexpect和这个SO答案。

#4


0  

You also need to ensure read and execute permissions for the user running that code on the directories up the chain - /Users, /Users/jondoe and /Users/jondoe/development.

您还需要确保在链上的目录上运行该代码的用户的读取和执行权限—/Users、/Users/jondoe和/Users/jondoe/development。