commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan McKinley <ryan...@gmail.com>
Subject Re: [exec] OutputStream to the input of the exec process
Date Thu, 24 Sep 2009 01:00:04 GMT
I'm new to commons exec.... but why not just:

DefaultExecutor executor = new DefaultExecutor();
ByteArrayOutputStream out = new ByteArrayOutputStream();
executor.setStreamHandler(new PumpStreamHandler( out ) )
int exitValue = executor.execute(commandLine);
String txt = out.toString();



On Sep 23, 2009, at 8:44 PM, Arun Ramakrishnan wrote:

> This is a follow up of my previous Question regarding similar topic.
>
> How do i get hold of an outputStream to the input of the binary i am  
> trying to wrap using Apache Commons Exec ?
>
> I see, then can you tell me whats wrong with this approach ? Nothing  
> seems to go to the input of tool.exe.
>
> I should probably post on apache commons forums, will do that if i  
> cant get any response here.
>
> I apologise for the groovy code.
>
>
> import org.apache.commons.exec.*;
>
> String line = "tool.exe" ;
> CommandLine commandLine = CommandLine.parse(line);
>
>
> commandLine.addArgument("engita")
> DefaultExecutor executor = new DefaultExecutor();
>
> def os =  new BufferedOutputStream(new ByteArrayOutputStream());
>
> PumpStreamHandler ioh = new PumpStreamHandler();
> ioh.setProcessInputStream(os)
> ioh.start()
> executor.setStreamHandler(ioh)
> String s = "hi there \n";
> [1..10].each{
> os.write(s.getBytes());
> }
> //os.close();
> int exitValue = executor.execute(commandLine);
> println " execution started"
> println exitValue;


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message