Sign in to follow this  
Followers 0

[Java] Print output of shell command

1 post in this topic

So Im working on a little project right now and currently im trying to run a shell command under java.

Everything works great, except I cant print the output of the shell command until its completely done executing. For this example / testing im using the rsync command in bash. How can I get java to print out whats happening in shell?

This code is running in its own method and in another thread so the ActionListener I add to the button that'll execute it wont hold it up. Its working like I expect except for it not printing right away. A lot of stuff online says to redraw / update, but i've done both to my Text Area and nothing.

Any ideas guys?


// Trial Code

String shellcommand = new String("");
shellcommand = "time rsync -Phav /Users/sikh/Downloads/ /Users/sikh/Desktop/Test";

Runtime run = Runtime.getRuntime();
Process cmdProcess = null;

try {
cmdProcess = run.exec(shellcommand);
} catch (IOException e) {

try {
} catch (InterruptedException e) {

BufferedReader reader = new BufferedReader(new InputStreamReader(cmdProcess.getInputStream()));
String line = "";
try {
while ((line = reader.readLine()) != null)
} // end while
} catch (IOException e) {
} // end try

// End Trial Code

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.