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

  • SEARCH
  • Home
  • 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 584065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:51:32+00:00 2026-05-13T14:51:32+00:00

def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + MyLog.txt,w) #new path

  • 0
def StartProc(dir, parm):
    global proc    

    proc_log = open(dir + os.sep + "MyLog.txt","w")  #new path for each file

    if parm:
        proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None)
    else:
        MyReset(proc)                     #reset the process(proc) to its default values
        proc.stdout = proc_log            #no effect
        print "fptr ", proc.stdout
    #endif
#enddef

prm = True

for i in range(0, 5):
    StartProc(i, prm)
    prm = False
#endfor

What I want to do is to start an executable only once, but on each iteration I want to redirect the process output to a different file. What is happening, is that files are created in the different path, but output is redirected to the file that is created first time.

Note: MyReset() initializes the process (executable) to its default values after the first iteration.

Will the following line change the process stdout to new file?

proc.stdout = proc_log
  • 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-05-13T14:51:33+00:00Added an answer on May 13, 2026 at 2:51 pm

    Like unwind said, you cannot change the file descriptor that the child process is writing its output to.

    What you can do, is read the output from the child process in your python script and then write it back to whatever file you want to. E.g.:

    proc = subprocess.Popen(path, 0, None, subprocess.PIPE, subprocess.PIPE, None)
    
    for l in proc.stdout.readlines():
      output_file.write(l)
    

    Obivously, you’ll need to figure out how control should behave in your app, i.e. can you do the writing from the main thread, when should the main thread return from StartProc() in that case, or do you have to do the writing from another thread so that the main thread can return from StartProc() immediately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def load_lib path = File.join(File.dirname(__FILE__), 'lib') failures = [] Dir.glob(#{path}/**/*.rb).each { |file| puts loading:
def get_type x = [{:type=>'A', :patterns=>['foo.*']}, {:type=>'B', :patterns=>['bar.*']}] name = 'foo.txt' result = x.each
def initialize(apps, catch=404) @apps = []; @has_app = {} apps.each { |app| add app
def leopardRemoveWireless(networkName): plistPath = '/Library/Preferences/SystemConfiguration/preferences.plist' # Sanity checks for the plist if os.path.exists(plistPath): try:
def new @user = User.find(session[:this_user]) @message = Message.new @people= People.order(is_active DESC, first_name, last_name) end
def refresh_menu @menu_pages = [] $menu_items.each do |id| @menu_pages[id - 1] = Page.find(id) end
def path(request, mypath): mypath = request.path_info _listdir = os.listdir(mypath) # ['folder1', 'folder2', 'folder3', 'folder4']
def PortScanWin(): win2 = Toplevel() win2.title(PortScan) win2.wm_maxsize(width='190',height='370') win2.wm_minsize(width='190',height='370') def go(): global app result.delete(1.0,END) app=scan()
def pad_image(f, width=500, height=None): if height==None: height = width image = Image.new(RGB, (800, 600),
def get_pkgs(): pkgs = [] for importer, modname, ispkg in \ pkgutil.walk_packages(path=None, onerror=lambda x:

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.