[3575] in java-interest

home help back first fref pref prev next nref lref last post

Process questions and problems

daemon@ATHENA.MIT.EDU (Anselm Baird_smith)
Thu Nov 16 13:22:54 1995

Date: Thu, 16 Nov 1995 16:15:19 +0100
From: Anselm Baird_smith <Anselm.Baird_Smith@inria.fr>
To: java-interest@java.sun.com
Reply-To: Anselm Baird-Smith <Anselm.BairdSmith@inria.fr>


Hello,

I am still having a few problems with the Process class:
[using latest jdk-beta on solaris 2.4: 
JDK-beta-solaris2-sparc.tar.Z, length=4569726]

a) Is there any mean to redirect stdin and stdout at exec time ? (I
   didn't try setting System.in & System.out, because I am looking for
   a better solution - e.g.: exec (String[], InputStream ,
   OutputStream). As a solution, I use the following class:

----------------------------------------------------
class ProcessFeeder extends Thread {
    Process      proc    = null ;
    OutputStream out     = null ;
    InputStream  in      = null ;
    int          count = -1 ;

    public void run () {
	try {
	    byte buffer[] = new byte[4096] ;
	    int  got      = -1 ;
	    
	    // Send the data to the target process:
	    if ( count >= 0 ) {
		while ( (count > 0) && ((got = in.read(buffer)) > 0) ) {
		    out.write (buffer, 0, got) ;
		    count -= got ;
		}
	    } else {
		while ( (got = in.read(buffer)) > 0 ) {
		    out.write (buffer, 0, got) ;
		}
	    }
	    // Clean up the process:
	    out.flush() ;
	    out.close() ;
	    proc.waitFor() ;
	} catch (Exception e) {
	    System.out.println ("ProcessFeeder: caught eexception !") ;
	    e.printStackTrace() ;
	}
    }
	
    ProcessFeeder (Process proc, InputStream in) {
	this (proc, in, -1) ;
    }
	
    ProcessFeeder (Process proc, InputStream in, int count) {
	this.proc   = proc ;
	this.out    = proc.getOutputStream() ;
	this.in     = in ;
	this.count  = count ;
    }
}
----------------------------------------------------------

Although I would rather like to spare this thread by setting the
process Input to the adequat object.

b) When using this class, the other thread reading
process.getInputStream() never gets an EOF, although the ProcessFeeder
tells me that the process has been waited for. Is this a bug ?

Thanks,
Anselm.


-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post