From f6e7f9c4de7f82e24f1e8baca9e26fbfb2fed683 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 15 May 2026 04:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20subprocess=20open=20test?= =?UTF-8?q?=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subprocess_open_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 subprocess_open_test.py diff --git a/subprocess_open_test.py b/subprocess_open_test.py new file mode 100644 index 0000000..ce32e9c --- /dev/null +++ b/subprocess_open_test.py @@ -0,0 +1,17 @@ +#!/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)