🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19801

outputstream to system command stdin in Java

#19801
From: Harry Yang
Date: Thu, 18 Dec 1997 00:00
62 lines
2434 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: <67bsfq$cgv7@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,cab3f647e513333c
X-Google-Attributes: gidf74b3,public
From: hyang04@cs.fiu.edu (Harry Yang)
Subject: outputstream to system command stdin in Java
Date: 1997/12/18
Message-ID: <67bsfq$cgv7@forums.borland.com>
X-Deja-AN: 299414570
Organization: School of Computer Science, Florida International University
Newsgroups: borland.public.jbuilder.java.language