Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:32:11+00:00 2026-06-16T03:32:11+00:00

According to the documentation if I use open(file,a) and write to the file the

  • 0

According to the documentation if I use open(“file”,”a”) and write to the file the new data would be appended, but in the example below the second command just overwrites the file. I don’t quite get 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 mode “a+b”, but I get the same end result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:32:12+00:00Added an answer on June 16, 2026 at 3:32 am

    Within the subprocess the file position is not increased. log.tell() returns 0 in the second with statement. You can incease the position of log to the end of the file. And it seems to be good to wait() for the first Process. Following works for me:

    import subprocess
    from os import linesep, stat 
    
    with open(r"test.txt","a") as log:
        Process = subprocess.Popen(['dir'],
                                   stdout = log, stderr = log,
                                   shell=True)
        Process.wait()
    
    with open(r"test.txt","a") as log:
    # this prints 0
        print log.tell()
    # get the length of the file log
        pos = stat(r"test.txt").st_size
        print pos
    # go to the end of log
        log.seek(pos)
        Process = subprocess.Popen(['dir'],
                                   stdout = log, stderr = log,
                                   shell=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to use doctrine with my mamp. but according to doctrine's documentation it
I can use intval , but according to the documentation: Strings will most likely
According to jQuery's .data() documentation you can use the .data() method to data prefixed
I'm trying to use the function XLookupString . According to the documentation , it
According to the its documentation csv.writer should use '\r\n' as lineterminator by default. import
According to MSDN documentation for RandomNumberGenerator : Application code does not directly use this
According to apple documentation of NSFetchedResultsController : You use a fetched results controller to
According to documentation, I try to subclass NSTextStorage and use it in text view:
I want to use MDM to manage number of iOS devices. According to documentation
According documentation Google App Engine could send mail but from restricted list of addresses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.