ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e <l...@menta.net>
Subject Redirection of the standar input of Java Task
Date Fri, 14 Jun 2002 15:22:03 GMT
Few days ago I asked the way to redirect the standard input of the Java Task,
I've found a solution (at the end of the message) but it doesn't accept the 
fork option.
I would like to use the fork option for security reasons, but I don't know 
how to do it. I've been trying diferent things with no luck :-(

Any ideas?
Thanks!

* Ermengol *

----------------------------------------------------------------------------------------------------
import java.io.*;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.*;

/**
* Extension of the org.apache.tools.ant.taskdefs.Java in order to enable
* the redirection of the Standar Input of the Java application loadded.
* It just add another param to the Java task, "input".
* By now, it doesn't accept the fork option, because then I don't know
* how to make the redirection :-/, and it gets hung...
* Any ideas will be welcome
* 14 june 2002.
* @author ebota@uoc.edu
*/
public class InOutJava extends org.apache.tools.ant.taskdefs.Java
{

	InputStream origIn= System.in;
	InputStream stdin= null;

	public InOutJava () {
		super();				
	}

      /** It controls that fork it's not enabled
      */
      public void setFork(boolean b) throws BuildException {
	     if (b) {
		     String msg="InOutJava: Fork not available when redirecting standar 
input";
		     log(msg, Project.MSG_ERR);
		     throw new BuildException(msg);
	     }
	     else super.setFork(b);
      }

      /** The new Standard Input
      */
      public void setInput(File in) {
	     try {
	     stdin= new FileInputStream(in);
	     } catch (IOException e) {	
		     String msg="InOutJava error opening input file";
		     log(msg, Project.MSG_ERR);
		     throw new BuildException(msg,e);
	     }
      }

      public void execute()  {
		try {			
			System.setIn ( stdin );
			super.execute();
			stdin.close();
			System.setIn(origIn);			
		} catch (Exception e) {
			System.out.println("InOutJava Error: "+ e);
		}		
	}	
}
  


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message