18 lines
390 B
Python
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)
|