You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-user@db.apache.org by Mike Baranski <li...@secmgmt.com> on 2009/11/05 17:38:47 UTC
[exec] PumpStreamHandler Example?
Can someone point me at an example? I need to execute a command and get
the output, which I can do with this class, I just can't figure out how to
hook the darned thing to a command...
RE: [exec] PumpStreamHandler Example?
Posted by Mike Baranski <li...@secmgmt.com>.
Duh, guess I should have used CommandLine.parse, instead of the constructor.
>-----Original Message-----
>From: Mike Baranski [mailto:list-subscriptions@secmgmt.com]
>Sent: Friday, November 06, 2009 9:05 AM
>To: 'DB Commons Users List'
>Subject: RE: [exec] PumpStreamHandler Example?
>
>I have the following:
>
>public static void main(String a[]) throws Exception
> {
> ByteArrayOutputStream stdout = new ByteArrayOutputStream();
> PumpStreamHandler psh = new PumpStreamHandler(stdout);
> CommandLine cl = new CommandLine("ls -al");
> DefaultExecutor exec = new DefaultExecutor();
> exec.setStreamHandler(psh);
> exec.execute(cl);
> System.out.println(stdout.toString());
> }
>
>And it gives:
>
>Exception in thread "main" java.io.IOException: java.io.IOException: ls
>-al:
>not found
> at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
> at java.lang.ProcessImpl.start(ProcessImpl.java:65)
> at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
> at java.lang.Runtime.exec(Runtime.java:591)
> at
>org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13Comman
>dLau
>ncher.java:58)
> at
>org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
> at
>org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.
>java
>:302)
> at
>org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149
>)
> at
>org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:136
>)
> at TpsMode.main(TpsMode.java:13)
>
>Any ideas?
>
>>-----Original Message-----
>>From: Mike Baranski [mailto:list-subscriptions@secmgmt.com]
>>Sent: Thursday, November 05, 2009 11:39 AM
>>To: commons-user@db.apache.org
>>Subject: [exec] PumpStreamHandler Example?
>>
>>Can someone point me at an example? I need to execute a command and
>>get
>>the output, which I can do with this class, I just can't figure out how
>>to
>>hook the darned thing to a command...
RE: [exec] PumpStreamHandler Example?
Posted by Mike Baranski <li...@secmgmt.com>.
I have the following:
public static void main(String a[]) throws Exception
{
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(stdout);
CommandLine cl = new CommandLine("ls -al");
DefaultExecutor exec = new DefaultExecutor();
exec.setStreamHandler(psh);
exec.execute(cl);
System.out.println(stdout.toString());
}
And it gives:
Exception in thread "main" java.io.IOException: java.io.IOException: ls -al:
not found
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
at java.lang.Runtime.exec(Runtime.java:591)
at
org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLau
ncher.java:58)
at
org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java
:302)
at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:136)
at TpsMode.main(TpsMode.java:13)
Any ideas?
>-----Original Message-----
>From: Mike Baranski [mailto:list-subscriptions@secmgmt.com]
>Sent: Thursday, November 05, 2009 11:39 AM
>To: commons-user@db.apache.org
>Subject: [exec] PumpStreamHandler Example?
>
>Can someone point me at an example? I need to execute a command and
>get
>the output, which I can do with this class, I just can't figure out how
>to
>hook the darned thing to a command...