www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to do piping in java?

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    How to do piping in java?

    Hi all

    I am new to this forum so would like to greet all who have been here since long helping others and wish i will get the same response too. I have a lot of questions to ask but am beginning with a problem that i am currently stuck in.

    How to do piping in java? i want to copy the input given by a user in a particular software to the clipboard and get it pasted to any other software. For this i wanna use piping concept in java

    Can anyone help to pipe two objects in java?

    Thanks

  2. #2
    Join Date
    Mar 2010
    Location
    Singapore
    Posts
    367
    Quote Originally Posted by ibosstech View Post
    Hi all
    I am new to this forum so would like to greet all who have been here since long helping others and wish i will get the same response too. I have a lot of questions to ask but am beginning with a problem that i am currently stuck in.

    How to do piping in java? i want to copy the input given by a user in a particular software to the clipboard and get it pasted to any other software. For this i wanna use piping concept in java

    Can anyone help to pipe two objects in java?

    Thanks
    Unlike scripting language, Java is a compiled language and therefore piping feature you want in Java is via the Java SDK API. Please see below sample.

    Code:
    try {
      String cmdString = "<put the command you want to read it's output from here>";
      Runtime r = Runtime.getRuntime();
      Process child = r.exec(cmdString);            
      InputStreamReader isr = new InputStreamReader(child.getInputStream());
      BufferedReader br = new BufferedReader(isr);
      String line = null;
      while ( (line = br.readLine()) != null) System.out.println(line);
      int res = child.waitFor();            
    } catch (InterruptedException ie) {
      System.out.println(ie.getMessage());
    } catch (IOException ioe) {
      System.out.println(ioe.getMessage());
    }

  3. #3
    Join Date
    Jan 2009
    Posts
    3,346
    As an alternative to trying to manipulate specific applications you can use the built in features of Java to copy specified text to the system clipboard which can then be pasted wherever you like.

    http://www.exampledepot.com/egs/java...er/ToClip.html

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles