【发布时间】:2023-12-10 14:16:01
【问题描述】:
在 Unix 上,如何将 ksh 函数的输出作为 Python 变量检索?
该函数称为sset,并在我的“.kshrc”中定义。
我根据评论建议尝试使用subparser 模块。这是我想出的:
import shlex
import subprocess
command_line = "/bin/ksh -c \". /Home/user/.khsrc && sset \""
s = shlex.shlex(command_line)
subprocess.call(list(s))
我得到一个Permission denied 错误。这是回溯:
Traceback (most recent call last):
File "./pymss_os.py", line 9, in <module>
subprocess.call(list(s))
File "/Soft/summit/tools/Python-2.7.2/Lib/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/Soft/summit/tools/Python-2.7.2/Lib/subprocess.py", line 679, in __init__
errread, errwrite)
File "/Soft/summit/tools/Python-2.7.2/Lib/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
额外细节:
- Python 2.7
- Ksh 版本 M-11/16/88i
- Solaris 10 (SunOS 5.10)
【问题讨论】:
-
搜索。这里有一个提示。在此处搜索“子进程”、“收集输出”和“python”。