You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Arun Ramakrishnan <ar...@languageweaver.com> on 2009/09/24 02:44:55 UTC

[exec] OutputStream to the input of the exec process

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;

RE: [exec] OutputStream to the input of the exec process

Posted by Arun Ramakrishnan <ar...@languageweaver.com>.
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


Re: [exec] OutputStream to the input of the exec process

Posted by Ryan McKinley <ry...@gmail.com>.
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