我想在我通过lessc读取/处理过的一些东西上运行lessc,并且不想弄乱文件。subprocess.check_output 和 Popen.communicate 都被证明是为了快速调整而带来的麻烦。他们都没有输出任何东西/永远等待。是否有某种无忧的便利功能来管理缓冲区等等?
示例来源:
from subprocess import Popen
from sys import stderr
s = """
@a: 10px
foo {
width: @a;
}
"""
print("making")
p = Popen("lessc -", shell=True, stdout=-1, stdin=-1, stderr=stderr)
print("writing")
p.stdin.write(bytes(s, "utf-8"))
print("Waiting")
p.wait()
print("readng")
out = p.stdout.read()
print(out)
输出:
making
writing
Waiting
(注释掉等待部分只会使它阻塞阅读)