If I understood it right, programs that can throw their output into a
pipe like ls or dir in fact write into standard input (e.g. ls -al | grep). How can I read with NetRexx/Java from this pipe/standard input? TIA kp -- K.P.Kirchdoerfer Voice: +49 431 15479 24116 Kiel E-Mail: [hidden email] The Mission Is Terminated (TG 1982) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to [hidden email] with the following message in the body of the note unsubscribe ibm-netrexx <e-mail address> |
-----BEGIN PGP SIGNED MESSAGE-----
On Tue, 26 May 1998 21:45:15 +0100, K.-P. Kirchdrfer wrote: >If I understood it right, programs that can throw their output into a >pipe like ls or dir in fact write into standard input (e.g. ls -al | >grep). How can I read with NetRexx/Java from this pipe/standard >input? Here is a fragment from the njpipes command stage that show a way to do this: - -------------------------- method runCommand(a=rexx) private do r = Runtime.getRuntime p = r.exec(a) catch IOException exit(13) end in = PrintWriter(p.getOutputStream()) do selectinput(1) loop forever in.println(String peekto()) readto() end catch StageError finally in.close() end out = BufferedReader(InputStreamReader(p.getInputStream())) do selectoutput(0) catch StageError end outputLines(out) err = BufferedReader(InputStreamReader(p.getErrorStream())) do selectoutput(1) catch StageError end outputLines(err) do p.waitfor() - -- say p.exitValue() selectoutput(2) output(Rexx p.exitValue()) catch StageError rc = rc() catch InterruptedException rc = 16 end p.destroy() - ----------------- Hope this helps, Luck, Ed Tomlinson ([hidden email]) Montreal, Canada To obtain my public key mail me with a subject of: PGP Key -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQEVAwUBNWtJeDaYyP7siYcJAQHligf/Q0UzNX1g9yjkReCwu8UDMKJt4vFkfOVD PeLR9ADZdk2tAth3W6yjzYmDjuABQiZZRI7zRFmbHpUg2pWzyh2OwDOGE8HyUjke T8pI6YWLlaf7b+0nMAYwuFrPCXTsFLrNl+mLKUwkPnD/96vnRoGJz96KRsj0vbbS zItO9rjpZZAys/KZ8ilJpxcH19nC+ZkVCaO3JnR8UVjPgV0xqaQRsnRILJ89U4cD 2NBIuXpTavvk9EGDHCFWwch57xp4de7ni9/uW3BUzF9IYY5qASvXJaAS388MveQS FSy43FVk+yhQhOwXCvUzhO4Rbj45rQxUKAR0S6P+Wy+6CiiI7uiWUg==KdxC -----END PGP SIGNATURE----- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to [hidden email] with the following message in the body of the note unsubscribe ibm-netrexx <e-mail address> |
In reply to this post by K.-P. Kirchdoerfer
On Tue, 26 May 1998 18:00:11 -0500, Ed Tomlinson wrote:
>On Tue, 26 May 1998 21:45:15 +0100, K.-P. Kirchdörfer wrote: > >>If I understood it right, programs that can throw their output into a >>pipe like ls or dir in fact write into standard input (e.g. ls -al | >>grep). How can I read with NetRexx/Java from this pipe/standard >>input? > >Here is a fragment from the njpipes command stage that show a way to >do this: >-------------------------- >method runCommand(a=rexx) private > > do > r = Runtime.getRuntime > p = r.exec(a) > catch IOException > exit(13) > end > > in = PrintWriter(p.getOutputStream()) > do > selectinput(1) > loop forever > in.println(String peekto()) > readto() > end > catch StageError > finally > in.close() > end Thanks for that one; but what you are doing here is to create a subprocess within your java class and then getting the I/O-streams of the _subprocess_. Your solution is a nice way to deal with outputstreams (standard and error) of a native program started from a java program in the systems runtime. I was looking the systems standardinputstream - like in teh example - ls | grep - e.g. I want to write grep.class (no, I won't do that) and how can I catch the output of ls? Well after looking into the java programmers faq, with some hints to related problems and again reading the docs more carefully I found java.lang.system with the var in, which has the output of e.g. ls already, I just have to read it. Pretty simple, if one only find the right way to do it. regards kp -- K.P.Kirchdoerfer Voice: +49 431 15479 24116 Kiel E-Mail: [hidden email] Suicide is painless ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to [hidden email] with the following message in the body of the note unsubscribe ibm-netrexx <e-mail address> |
In reply to this post by K.-P. Kirchdoerfer
If reading it line-by-line is OK, try using the NetRexx special word ASK. It
returns the next line from System.in. Here's the codeit uses: properties private static StdIn =BufferedReader(InputStreamReader(System.in)) /* <sgml> Function to return a line read from the standard input stream |
In reply to this post by K.-P. Kirchdoerfer
> From: "K.-P._Kirchdörfer" <[hidden email]> > Well after looking into the java programmers faq, with some hints to > related problems and again reading the docs more carefully I found > java.lang.system with the var in, which has the output of e.g. ls > already, I just have to read it. Pretty simple, if one only find the > right way to do it. Well, a simple solution is to use "ask". The following code implements a simple filter which displays lines containing a given string: -- ngrep.nrx loop forever curline = ask if curline.pos(arg) > 0 then say curline catch NullPointerException end You use it the following way: {0}[E:\LOCAL\nrx] dir | java ngrep "<DIR>" 13/05/97 19:29 <DIR> 0 . 13/05/97 19:29 <DIR> 0 .. 18/01/98 21:57 <DIR> 0 ctr [Catching NullPointerExceptions is not a recommended practice, but is here needed.] Martin -- [hidden email] Team OS/2 http://www.mygale.org/~lafaix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to [hidden email] with the following message in the body of the note unsubscribe ibm-netrexx <e-mail address> |
In reply to this post by K.-P. Kirchdoerfer
Thanks for all the input;
small question, but learned more than asked :) >Well, a simple solution is to use "ask". The following code >implements a simple filter which displays lines containing a given >string: I wasn't shure, if the input will be line-oriented, therefor I used a less readable and more java-like solution to read the input into a 2kb buffer and write to a file until all is done. Both solutions, ask() and the one described, will do the work ('cause the input in fact _is_ always line-oriented), I'm now wondering which one would be faster. This raises a more general question for me. I use whereever possible NetRexx and a (net)rexxish style for programming, 'cause it's so easy. Does this style have an impact on the performance? In the above case, doing the job with ask() is simple. easy to understand, and very few lines of code; doing it with a bufferedinputstream and reading it into a buffer is less readable, and possibly introduces bugs, 'cause it's more complicated, needs more lines of code..., but will it run better without using the netrexx runtime? regards kp -- K.P.Kirchdoerfer Voice: +49 431 15479 24116 Kiel E-Mail: [hidden email] Mission Of Dead Souls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to [hidden email] with the following message in the body of the note unsubscribe ibm-netrexx <e-mail address> |
Free forum by Nabble | Edit this page |