Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: get terminal value back to ide?

  1. #1
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default get terminal value back to ide?

    hi im using ubuntu an if i run the command
    wget http://ipecho.net/plain -O - -q ; echo
    then my external ip is displayed in the terminal but if i run this with runtime... in java how do i get the value back to java ? cant assigne it to string ,the toString() just give memery location and there are no other aplicable methods does any know of a way cos all i can think of doing is writing it to a file and scanning it and damb it im sick of writing stuff to files


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: get terminal value back to ide?

    Use the InputStream/OutputStream objects returned by the respective methods in the Process class returned by Runtime.exec to communicate with the process. And some further reading:
    http://www.javaworld.com/jw-12-2000/jw-1229-traps.html

  3. #3
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: get terminal value back to ide?

    Quote Originally Posted by copeg View Post
    Use the InputStream/OutputStream objects returned by the respective methods in the Process class returned by Runtime.exec to communicate with the process. And some further reading:
    When Runtime.exec() won't - JavaWorld
    thanks found th answer at that link
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("wget http://ipecho.net/plain -O - -q ; echo");
                InputStream stderr = proc.getInputStream();
                InputStreamReader isr = new InputStreamReader(stderr);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                while ( (line = br.readLine()) != null)
                    System.out.println(line);

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: get terminal value back to ide?

    Just wondering, but is there some reason why you are using wget?

    wget is a commandline/console tool for reading what servers produce when you hit them with a url. Consider wget a "square peg" and - as the JavaWorld article suggests - a Java application is something of a "round hole". Using wget from within a Java application involves all sorts of mucking about with streams (and the exceptions they might cause). But Java has all sorts of perfectly good ("round peg") networking classes and methods that could be used to directly get the text that http://ipecho.net/plain returns.

    See Reading Directly from a URL in Oracle's Tutorial. And the surrounding pages.

  5. #5
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: get terminal value back to ide?

    Quote Originally Posted by pbrockway2 View Post
    Just wondering, but is there some reason why you are using wget?

    wget is a commandline/console tool for reading what servers produce when you hit them with a url. Consider wget a "square peg" and - as the JavaWorld article suggests - a Java application is something of a "round hole". Using wget from within a Java application involves all sorts of mucking about with streams (and the exceptions they might cause). But Java has all sorts of perfectly good ("round peg") networking classes and methods that could be used to directly get the text that http://ipecho.net/plain returns.

    See Reading Directly from a URL in Oracle's Tutorial. And the surrounding pages.
    a right i was using that command in terminal and movd to ide but your not just right your damb right thanks

  6. #6
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: get terminal value back to ide?

    I'm the same. If I know something is effective in one place, the most natural thing is to try it elsewhere...

    wget rocks, but it's natural home is within bash scripts etc. If you do try the approach suggested in the Tutorial and get stuck, you can always ask about that.

Similar Threads

  1. Integrated Java With Terminal
    By MFD-Stark in forum Java Theory & Questions
    Replies: 2
    Last Post: January 2nd, 2013, 12:23 PM
  2. [SOLVED] GUI: Moving away from the terminal
    By hippoCase in forum Java Theory & Questions
    Replies: 3
    Last Post: June 11th, 2012, 02:17 PM
  3. Terminal Tamagotchi
    By FlurrYx in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2011, 01:05 PM
  4. Quick help with using linux terminal
    By Stockholm Syndrome in forum Java Theory & Questions
    Replies: 0
    Last Post: April 1st, 2011, 09:28 AM