commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arun Ramakrishnan <aramakrish...@languageweaver.com>
Subject RE: [exec] OutputStream to the input of the exec process
Date Thu, 24 Sep 2009 02:43:32 GMT
Its not the output of binary I need help with, but with passing input to it.
I think I said, "OutputStream to the input of the binary". I am not sure if that's an accurate
description.


-----Original Message-----
From: Ryan McKinley [mailto:ryantxu@gmail.com] 
Sent: Wednesday, September 23, 2009 6:00 PM
To: Commons Users List
Subject: Re: [exec] OutputStream to the input of the exec process

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


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


Mime
View raw message