Files
python-tests/subprocess_tests/subprocess_open_test.py
T

18 lines
390 B
Python

#!/usr/bin/env python3
import subprocess
from pathlib import Path
if __name__ == "__main__":
with open("output.log", "w") as f:
process = subprocess.Popen(
["ls", "-l"],
# cwd="/tmp",
stdout=f,
stderr=f,
)
process.wait() # 等待进程结束
t = Path("output.log").read_text(encoding="utf-8")
print(t)