Article View: borland.public.jbuilder.java.api
Article #3450outputstream to system command stdin in Java
From: Harry Yang
Date: Thu, 18 Dec 1997 00:00
Date: Thu, 18 Dec 1997 00:00
62 lines
2437 bytes
2437 bytes
I tried to send a output stream to a system command stdin in Java. It can
works in Unix, but can't in Windows NT. Does any body know what is the point?
Following is the system command I tested.
---------------------------------------------------
#include <iostream.h>
main()
{
int c;
while ((c=cin.get())!=EOF)
cout << (char) c;
return 0;
}
-----------------------------------------------------
Following is the Java program that execs above command "mycat" and send
string to it.
------------------------------------------------------
import java.io.*;
class MyTest {
public static void main(String[] args) {
try{
String line;
Process p = Runtime.getRuntime().exec("mycat");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
DataOutputStream output = new DataOutputStream(p.getOutputStream());
output.writeBytes("Change: new\n\nClient: camp.unix\n\n");
output.flush();
output.close();
while ((line = input.readLine() ) != null) {
System.out.println(line);
}
input.close();
p.waitFor();
}catch (Exception e){
System.out.println("exec fail:"+e.toString());
e.printStackTrace();
}
}
}
----------------------
When I run "java MyTest", it is waiting there, which looks like waiting a input
or waiting a end of stream signal. The only way to stop the program is Ctrl-C.
This happens on NT, but runs fine in Unix. Any help?
Harry
-~---~---~---~---~---~---~---~---~---~---~---~---~----~---~---~---~---~---~---
Hai (Harry) Yang .^* Everest, the highest point.
//.\\_
mailto: hyang04@cs.fiu.edu / Yang \._
hyang@poboxes.com -/^Hai Harry \------
http://www.geocities.com/MadisonAvenue/3131/
Technical Details
Message-ID:
<67ab53$bng5@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,20b800a2fc2f3b22,start X-Google-Attributes: gid1089d0,public From: hyang04@cs.fiu.edu (Harry Yang) Subject: outputstream to system command stdin in Java Date: 1997/12/18 Message-ID: <67ab53$bng5@forums.borland.com> X-Deja-AN: 299245826 Organization: School of Computer Science, Florida International University Newsgroups: borland.public.jbuilder.java.api