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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:31:42+00:00 2026-05-28T04:31:42+00:00

You can easily use exec() or shell_exec() to execute a system command, like ls

  • 0

You can easily use exec() or shell_exec() to execute a system command, like ls -l /var/www/mysite and then output the result of the command.

How would one execute and display the result of a command that periodically prints information out to the console?

You have a simply Python script. If you run the script from the console, it simply prints out some type of information to the console every 10 seconds forever until you force-quit the script.

How could use PHP to execute this python command and somehow capture and stream the output into the browser in realtime? Is something like this possible? I’m thinking there would have to be some sort of Ajax involved but I’m not sure.

I tried doing something like this:

python myscript.py > output.txt

And then I was planning on maybe using Ajax to periodically tail or cat the content of the output.txt and display in the browser. But output.txt doesn’t appear to have any content added to it until after the script has been force-quit.

  • 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-28T04:31:43+00:00Added an answer on May 28, 2026 at 4:31 am

    You don’t see any output to output.txt because it’s being buffered. For python there’s an option to make it line-buffered. From the manpage:

           -u     Force  the  binary I/O layers of stdin, stdout and stderr to be unbuffered.  The text I/O layer will still be
                  line-buffered.
    

    So your command would then become:

    python -u myscript.py > output.txt
    

    For PHP the flush function should help you.

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

Sidebar

Related Questions

In javascript you can easily create objects and Arrays like so: var aObject =
In MVC .NET application we can easily use PartialView to print the output of
In C# I use a Queue collection. I can easily Enqueue or Dequeue. Okay,
In Bash I can easily do something like command1 && command2 || command3 which
In C#, I can easily use @path to get path that is acceptable to
I'm trying to create a DSL that can easily use a dom node. Using
Unless this is HTML 5 where I can easily use history.pushState() to manipulate URL
I find myself assigning this to a variable so I can easily use it
Is there any DNS server written in python where I can easily use a
One can easily use JDO syntax to query on multiple parameters as follows: //specify

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.