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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:31:13+00:00 2026-06-11T09:31:13+00:00

I am writing a Python command line program. There is a main Python script

  • 0

I am writing a Python command line program.

There is a main Python script file, acting as the entry point. When user run this script, it will execute a few external Python script files. The external Python script files may also execute other external Python script files. The number of external files is variable.

The Python script will execute external Python scripts using:

p = subprocess.Popen(args)

or

p = subprocess.call(args)

When I run the main Python script in a terminal window, it will print real time log messages on the screen when it is running. Now, I would like to get all log messages from all external Python scripts called by the main Python script and print it onto the same terminal window (the terminal window that I use to run the main script).

For example, below are the sequence of script execution:

1.Main-script
    |
    2.Layer-1-script-1
        |
        3.Layer-2-script-1
        |
        4.Layer-2-script-2
        |
    5.Layer-1-script-2
    |
    6.Layer-1-script-3
    |
7.Main-script(continued)

When I run the main script in a terminal window, is it possible that I can get real time log messages on my terminal window like below?

[time-hh-mm-ss][log message from main script]Script is running..
[time-hh-mm-ss][log message from main script]Calling script layer-1-script-1..
[time-hh-mm-ss][log message from layer-1-script-1]Script is running..
[time-hh-mm-ss][log message from layer-1-script-1]Calling script layer-2-script-1..
[time-hh-mm-ss][log message from layer-2-script-1]Script is running..
[time-hh-mm-ss][log message from layer-2-script-1]Calling script layer-2-script-2..
[time-hh-mm-ss][log message from layer-2-script-2]Script is running..
[time-hh-mm-ss][log message from layer-2-script-2]Calling script layer-1-script-2..
[time-hh-mm-ss][log message from layer-1-script-2]Script is running..
[time-hh-mm-ss][log message from layer-1-script-2]Calling script layer-1-script-3..
[time-hh-mm-ss][log message from layer-2-script-3]Script is running..
[time-hh-mm-ss][log message from main script]Back to main script. Script is running..

Is it possible that I can get a real time log messages like above in the terminal window?

  • 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-11T09:31:15+00:00Added an answer on June 11, 2026 at 9:31 am

    If you have control over all the Python scripts, then you could use multiprocessing instead of subprocess with which you could do something like this:

    test.py:

    import logging
    import test2
    import multiprocessing as mp
    
    logger = mp.get_logger()
    
    def main():
        logger.info('Script is running')
        logger.info('Calling script test2')
        proc = mp.Process(target = test2.main)
        proc.start()
        proc.join()
    
    if __name__ == '__main__':
        formatter = logging.Formatter('[%(asctime)s] [%(filename)s]: %(message)s',
                                      datefmt = '%H:%M:%S')
        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        logger.setLevel(logging.INFO)    
        main()
    

    test2.py:

    import multiprocessing as mp
    
    logger = mp.get_logger()
    
    def main():
        logger.info('Script is running...')
    

    Running test.py yields

    [11:36:50] [test.py]: Script is running
    [11:36:50] [test.py]: Calling script test2
    [11:36:50] [util.py]: child process calling self.run()
    [11:36:50] [test2.py]: Script is running...
    [11:36:50] [util.py]: process shutting down
    [11:36:50] [util.py]: process exiting with exitcode 0
    [11:36:50] [util.py]: process shutting down
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a python command line script that takes a .ldif and two
I'm writing a program in Python that accepts command line arguments. I am parsing
I am writing code in Python that I should run with the command line
I'm new to python. I'm writing a script that calls a command line tool
Writing a python program, and I came up with this error while using the
Im new to python programming.Im writing a simple command line based twitter app,and i
On Windows 7, I have a command-line program that fails due to file write permission
I have a completely non-interactive python program that takes some command-line options and input
In a bit of Python I'm writing (a command line and filter testing tool:
I have been writing command-line Python scripts for a while, but recently I felt

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.