According to the documentation, if I use open ("file", "a") and write to a file, new data will be added, but in the example below, the second command simply overwrites the file. I donโt quite understand why.
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)
I already tried the "a + b" mode, but I get the same end result.
source share