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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:15:55+00:00 2026-05-23T16:15:55+00:00

The problem is this: I have a Python Script which generates Shell output. This

  • 0

The problem is this: I have a Python Script which generates Shell output. This output looks like this:

Result: good.

[123 SPEED] [456 GOOD] [789 BAD]

The last line updates itself and becomes either a result:good or result:bad line. Then again the last line updates itself and erases the previous one. I found a way how to disable this behaviour in the python script, but it would be nice to only regex the last line of the shell output w/o altering the python script.

Now if I let run this Java code over that output, it display not the wanted results, if any.

The timer runs like I expect it for the first 3 times, then it stops for 1 minute and then outputs 50 lines of regexed output and even the wrong one.

The desired result is to output the first bracket, the second bracket and the third bracket into distinct GUI Swing labels and then update these labels every n seconds from the python shell output.

        try {
            p = Runtime.getRuntime().exec("myScript.py -Switches");
            pReg = Pattern.compile("\\[(.*?)\\]");
            ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
            exec.scheduleAtFixedRate(new Runnable() {
              @Override
              public void run() {
                   try {
                      BufferedReader input =
                            new BufferedReader(new InputStreamReader(p.getInputStream()));
                        if ((line = input.readLine()) != null) {
                            // regex
                            Matcher m = pReg.matcher(line);
                            int h = 0;
                            while(m.find()) {
                               myHashArray[h] = m.group(1);
                               h++;
                               Sytem.out.println(m.group(1));
                            }
                        }
                  }
                   catch (IOException e1) {
                        System.err.println(e1);
                        System.exit(1);
                   }
                }
            }, 0, 500, TimeUnit.MILLISECONDS);
        }

        catch (IOException ea) {
            System.exit(0);
        }
  • 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-23T16:15:55+00:00Added an answer on May 23, 2026 at 4:15 pm

    Try not using a BufferedReader — use the InputStreamReader directly–

    Or have the python process output new lines between each bracketed item

    The BufferedStreamReader is waiting for the buffer to fill or for a new line before it returns anything to your Java process

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

Sidebar

Related Questions

I have a python script which should parse a file and produce some output
I have a python script which calls a lot of shell functions. The script
I have a PHP script which executes a shell command: $handle = popen('python last',
The problem is basically this, in python's gobject and gtk bindings. Assume we have
I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
I have a Python script which accepts a XML file as input and then
I'm trying to solve the following problem: Say I have a Python script (let's
I have a python script that makes an attribute table of a raster. This
I have a Python script which uses Tkinter for the GUI. My little script
I have a python script called mythicalPythonBindings.py. It outputs something like Establishing database connection

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.