根据文档,如果我使用 open("file","a") 并写入文件,新数据将被附加,但在下面的示例中,第二个命令只是覆盖文件。我不太明白为什么。
import subprocess
startupinfo = subprocess.STARTUPINFO()
subprocess.STARTF_USESHOWWINDOW = 1
startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
with open(r"c:\folder\test.txt","a") as log:
Process = subprocess.Popen(['dir'],
stdout = log, stderr = log,
startupinfo = startupinfo,
shell=True)
with open(r"c:\folder\test.txt","a") as log:
Process = subprocess.Popen(['dir'],
stdout = log, stderr = log,
startupinfo = startupinfo,
shell=True)
我已经尝试过模式“a+b”,但我得到了相同的最终结果。