what happens when you want to send a String of binary data as input to a process ?
b.getBinaryStream() just gets you a stream, it doesn't get you the data. You could either read in the stream, convert it to a String then invoke runtime.exec with the results (which would cause havoc with binary data), or if your programs accept input through system input, you could start sysproc with runtime.exec(), then get the output stream of that process and write your blob to it
One last question : Can you give me an example of how you would use those functions ...just so I can run it and see how they would be used in an actual program ? Im a little bit unfamiliar with I/O streams and pipes, so the concept of an InputStream and an OutputStream is a bit abstract to me.
From the posting time I believe this is a response to something I had briefly posted and then deleted. Sorry, I deleted my earlier post because I realized I'd misunderstood what you were asking for, making it more complex than necessary. Joe's earlier reply addressed your question better.
Here's a simple way to copy from the Blob to the Process though:
Note - no Strings are used here. At all. For binary data, it's usually a mistake to try to convert to a String unless you know that it's supposed to represent text. And for this problem, we don't really care whether it's a String or not.
I recommend studying the Java tutorial if you want to get more background on the IO classes.
I've also pretty much omitted error handling for simplicity. Normally I'd prefer something like
...and you still need to catch exceptions at a higher level, but the details of that will depend on the context. [ January 31, 2006: Message edited by: Jim Yingst ]
What operating system are you running this on? If it is a *nix platform, then you can easily do this with a shell script in one line:
The most difficult part is to figure out how process1 will input the first set of data. It can possibly come from a command-line argument (like a file name) or from stdin. In fact, most *nix utilities allow for both.
I think you can do this with a Windows batch file in a single line as well. As much as I enjoy programming in Java, sometimes it is not the right tool for the job. In this case, I think shell/batch scripts might be more useful.
I guess Im still a little confused. Shouldnt you be writing to the inputStream?
One writes to OutputStreams. One reads from InputStreams. I admit that it seems backwards in certain situations like the Process class.
Now, if the inputStream to a process is the stream of data which will be used as input to that process, wouldnt it be logical to do something like:
Again, getOutputStream() returns a stream. You still have to move the data in the manner Jim demonstrated. As Jim suggested, spend a little time going over the tutorial. Knowing the basics will help you a great deal in this task.
And as for the bottle of wine, I don't know when Jim, Layne and I will be able to sit down together to enjoy it. Consider making a small donation to the JavaRanch.