0

I am writing a Swing application that will execute long running perl scripts. I need to display the interim output of an execution concurrently even as the process executes in the background. Using the following piece of code returns the output at process completetion.

BufferedReader stdInput = new BufferedReader(new 
                     InputStreamReader(p.getInputStream()));

                // read the output from the command
                while ((s = stdInput.readLine()) != null) {
                    System.out.println(s);
                }

How can I get the ouput concurrently? I am using Swingworker to display the returned information.

1 Answer 1

1

Is autoflushing enabled on the Perl side? If not, then you'll be buffering.

Set $| to a non-zero value through $|++; or $| = 1; to enable autoflushing.

See perldoc perlvar for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

I would definitely recommend $| = 1; over $|++, as someone may have turned it on by using $|--. ( I have seen both $|++ and $|-- used here on StackOverflow, so this isn't an idle thought. ) At any-rate $| is a flag, and should be treated as such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.