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 3450964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:05:59+00:00 2026-05-18T09:05:59+00:00

Is there a way that I can run a script from another while getting

  • 0

Is there a way that I can run a script from another while getting output as readily as I get by executing it by itself.
For example:
I use the os.popen3 command to execute abc.py, but I am unable to get output from abc.py as readily as I would with doing python abc.py; it seems that I need to wait for os.popen3 command to finish:

fin, fout, ferr=os.popen3("abc.py")
out = fout.read()
err = ferr.read()
fo.write(out)
fe.write(err)
print out
print err

[EDIT]:fo and fe here are file handles to the output and error logs, respectively.

Also, what widget do I use to populate the output in, in pygtk?

  • 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-18T09:05:59+00:00Added an answer on May 18, 2026 at 9:05 am

    The subprocess module is the option, but the tricky part is to follow the output un parallel with your main loop of gtk, to accomplish that goal you must have to consider the platform that you are dealing, if you are in linux you can easily run another thread and use gtk.gdk.threads_init to use threads in pygtk, but if you are planing to run your application on windows, then you should use generators and gobject.idle_add.

    About the widget, use gtk.TextBuffer associated with a gtk.TextView

    Here is an example with threads

    import gtk
    import subprocess
    import threading
    
    gtk.gdk.threads_init()
    
    class FollowProcess(threading.Thread):
        def __init__(self, cmd, text_buffer):
            self.tb = text_buffer
            self.child = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            super(FollowProcess, self).__init__()
    
        def run(self):
            while not self.child.poll():
                out = self.child.stdout.read(1)
                if out != '':
                    gtk.gdk.threads_enter()
                    self.tb.insert_at_cursor(out)
                    gtk.gdk.threads_leave()
    
    def destroy(w, cmd):
        cmd.child.terminate()
        gtk.main_quit()
    
    i = 0
    def click_count(btn):
        global i
        message.set_text('Calling button %d' %i)
        i += 1
    
    other_command = 'python extranger.py'
    
    w = gtk.Window()
    w.resize(400, 400)
    
    message = gtk.Label('Nothing')
    tb = gtk.TextBuffer()
    tv = gtk.TextView(tb)
    scroll = gtk.ScrolledWindow()
    scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
    scroll.add(tv)
    
    box = gtk.VBox()
    button = gtk.Button('Active button')
    
    cmd = FollowProcess('python extranger.py', tb)
    
    button.connect('clicked', click_count )
    
    w.connect('destroy', destroy, cmd)
    box.pack_start(button, False)
    box.pack_start(message, False)
    box.pack_start(scroll)
    
    
    w.add(box)
    w.show_all()
    cmd.start()
    gtk.main()
    

    And in extranger.py

    import time
    import sys
    
    i = 0
    while True:
        print 'some output %d' % i
        sys.stdout.flush() # you need this to see the output
        time.sleep(.5)
        i += 1
    

    Note how the button stills responsive even with the update in parallel.

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

Sidebar

Related Questions

Is there a way that I can run a ASP.NET MVC Project on godaddy.com
Is there a way that I can get the last value (based on the
Is there a way that you can get a collection of all of the
Is there any way that I can programmatically create (and I guess access) hidden
Is there any way that I can change how a Literal of a code
Is there a way that you can have SERVEROUTPUT set to ON in sqlplus
Is there a way that I can configure Visual Studio 2008 to understand CamelCase?
Is there any way that I can find the container pointed to by an
Is there a way that I can create a function that takes an int
Is there any way so that i can echo password when asked for in

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.