C
Carfield Yim
I have some code like follow, which get some data from URL pipe to a
unix command, and get the result:
String line = "";
final Runtime rt = Runtime.getRuntime();
final Process p = rt.exec("somecommand");
final BufferedReader urlBR = new BufferedReader(new
InputStreamReader(new URL(url).openStream()));
final Writer os = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
while((line = urlBR.readLine()) != null) os.write(line);
os.close();
urlBR.close();
final BufferedReader din = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ( (line = din.readLine()) != null ) out.write(line);
din.close();
However it fail with "broken pipe" exception, I believe that as I don't
really pipe the data to the command, so java execute the command as
nothing output to the command.
Thus I try to use
final Process p = rt.exec("|somecommand");
But java complain command not find. How can I tell java that I have
something needed to pipe to the command?
--
\\\|///
\\- - -//
( @ @ )
-----------oOOo-(_)-oOOo------------------------------------------------
Visit my homepage at http://www.carfield.com.hk
Programming discussion groups
Software design: news://news.carfield.com.hk/programming.design
Design Pattern: news://news.carfield.com.hk/programming.design.pattern
java: news://news.carfield.com.hk/programming.java
linux: news://news.carfield.com.hk/programming.linux
------------------------------------------------------------------------
unix command, and get the result:
String line = "";
final Runtime rt = Runtime.getRuntime();
final Process p = rt.exec("somecommand");
final BufferedReader urlBR = new BufferedReader(new
InputStreamReader(new URL(url).openStream()));
final Writer os = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
while((line = urlBR.readLine()) != null) os.write(line);
os.close();
urlBR.close();
final BufferedReader din = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ( (line = din.readLine()) != null ) out.write(line);
din.close();
However it fail with "broken pipe" exception, I believe that as I don't
really pipe the data to the command, so java execute the command as
nothing output to the command.
Thus I try to use
final Process p = rt.exec("|somecommand");
But java complain command not find. How can I tell java that I have
something needed to pipe to the command?
--
\\\|///
\\- - -//
( @ @ )
-----------oOOo-(_)-oOOo------------------------------------------------
Visit my homepage at http://www.carfield.com.hk
Programming discussion groups
Software design: news://news.carfield.com.hk/programming.design
Design Pattern: news://news.carfield.com.hk/programming.design.pattern
java: news://news.carfield.com.hk/programming.java
linux: news://news.carfield.com.hk/programming.linux
------------------------------------------------------------------------