【发布时间】:2020-04-20 17:25:23
【问题描述】:
似乎与Using Python to open a shell environment, run a command and exit environment 重复。我想在 Redhat 的 shell 环境中运行 ulimit 命令。过程:打开shell环境,在shell上运行ulimit命令,得到结果并退出shell environmnet。参考上面的解决方案,我试过了:
from subprocess import Popen, PIPE
def read_limit():
p = Popen('sh', stdin=PIPE)
file_size = p.communicate('ulimit -n')
open_files = p.communicate('ulimit -f')
file_locks = p.communicate('ulimit -x')
return file_size, open_files, file_locks
但我收到错误:ValueError: I/O operation on closed file。
【问题讨论】:
标签: python