db-commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Baranski" <list-subscripti...@secmgmt.com>
Subject RE: [exec] PumpStreamHandler Example?
Date Fri, 06 Nov 2009 14:04:34 GMT
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...



Mime
View raw message