Results 1 to 7 of 7
Thread: Input redirection in Java
- 05-08-2009, 12:44 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
Input redirection in Java
Hi,
I've a perl script called process.pl which I use to invoke through unix client as shown below:
$ process < abc.txt
Now, abc.txt contains entries per line which is processed by this perl script.
I want to invoke this process script through Java. I've captured the input which is required for this script in StringBuffer. My question is how do I pass this input which I stored in stringbuffer to this script?
I've tried below command, but it takes only 1st string within my Stringbuffer.
Stringbuffer str; // This contains line by line input which is required for script
.....
Runtime.getRuntime().exec("process " + str);
But the above code executes & parses only 1st line in my stringbuffer. Can any one provide me the code which will take all input from this stringbuffer & pass it to process script??
Please note that I DO NOT want to create a file & then pass it to script.
Thanks in Advance!
- 05-08-2009, 01:19 AM #2
Process.getInputStream() and Process.getOutputStream() to communicate with an external process.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-08-2009, 01:23 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
Can you please provide me the code snipppt to pass stringbuffer to this output or input stream?
Thanks in Advance!
- 05-08-2009, 01:49 AM #4
Wrap the stream with a BufferedWriter and write() the contents of the StringBuffer.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-08-2009, 02:06 AM #5
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
Hi OrangeDog,
I really appreciate your response however, I'm not expert in Java.
So far, I've below code:
How do I write data from stringbuffer to outstream?Java Code:StringBuffer str= new StringBuffer(); str.append("1st line"); str.append("\n"); str.append("2nd line"); Process process = Runtime.getRuntime().exec("process " + str); OutputStream outStream = process.getOutputStream(); int exitVal = process.waitFor(); if (exitVal == 0) { result = true; } else { result = false; }
Appreciate any help!!
- 05-08-2009, 02:20 AM #6
What I said is explained here.
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
-
Similar Threads
-
redirection
By prashant in forum NetworkingReplies: 1Last Post: 02-25-2009, 02:53 PM -
Output Redirection
By Sixtease in forum New To JavaReplies: 8Last Post: 12-29-2008, 10:18 AM -
JSP redirection script
By ravian in forum New To JavaReplies: 1Last Post: 01-07-2008, 10:33 AM -
redirection in jsp
By valery in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-06-2007, 08:31 PM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks