/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@sohguanhApr 23.2010 — 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[/QUOTE]


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());
}

[/CODE]
Copy linkTweet thisAlerts:
@criterion9Apr 23.2010 — 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.awt.datatransfer/ToClip.html
×

Success!

Help @ibosstech spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...