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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:09:26+00:00 2026-06-10T04:09:26+00:00

I am currently working on a Java project that will allow me to text

  • 0

I am currently working on a Java project that will allow me to text edit, save, and then execute Python code. I have hit a snag with the execution of this code however.

For executing the code, I have been doing the following:

Process p = Runtime.getRuntime().exec("python someFileName.py",null,new File("someFilePath");

From here, I have a class that takes this process, and tries to take the input and output streams from the process. I have a Timer set with an action listener that will refresh every .01 second.

That is not the problem however. I can receive input just fine if my program consists solely of print statements in python.

If my program contains anything that requires it to block, either raw_input or time.sleep, nothing is displayed.

My actionPerformed method is as follows:

public void actionPerformed(ActionEvent e)
{
    try
    {
        while(inStream.available() > 0)
        {
            System.out.print((char)inStream.read());
        }
        while(errStream.available() > 0)
        {
            System.out.print((char)errStream.read());
        }
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
}

To handle output, I have a KeyListener on a JTextArea that will send the contents of that area to the output stream.

Whenever I have anything in my Python program that requires blocking, no matter what location in the program, the entire thing locks up.

For instance, I have this python program:

import time

print "Welcome to my Program!"
print "Performing calculations"
time.sleep(5)
num = 5
print "Adding 5 to your number"
for x in range(5):
    num+=1
    print num
print "Finished!"

Nothing will display for the time that it sleeps. I would assume that the things I receive in the Java program would be:

Welcome to my Program!
Performing calculations
…then nothing for five seconds…then
Adding 5 to your number
6
7
8
9
10
Finished!

But nothing is displayed at all until after 5 seconds has elapsed. So I can execute the program, wait 5 seconds, then a flood of text appears.

Or for using raw_input, the same thing happens. So in other words I cannot use this to prompt users for input.

I was hoping I could get some help with this blocking issue so that my text displays gradually as opposed to having to wait for everything to get out of the way with timers or input.

Any help or resources are appreciated. My current OS is a Mac, but I want any solution to be workable on Windows as well (if at all possible).

  • 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-10T04:09:28+00:00Added an answer on June 10, 2026 at 4:09 am

    By default, python scripts run with buffered output. That means you may not see any stdout until the script exits and flushes. All you have to do is launch python with -u to request unbuffered output. Then you will see what you were expecting.

    python -u someFileName.py
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project in Java, that will allow users to type
I'm working on code for a Java project, I currently have replaceAll(String, int) in
I'm currently working on a java project that requires me to make a system
I'm currently working on a project that is building a java-based desktop application to
I'm currently working on a Java project that is emitting the following warning when
I am currently working on a mantenance project that is written in Java. We
I'm currently working on a project that is done in Java, on google appengine.
I'm working on project that will work real time: I have to write a
I'm currently working on a project where we have a Java web app bought
I am currently working on a project that is very new to me, and

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.