You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Lukas Bradley <lu...@somnia.com> on 2005/03/30 16:09:11 UTC

Runtime.exec() Utilities?

Is there ANYTHING out there that can help manage executing system 
commands to batch input, capture output, and generally not make a mess 
of things on different platforms?

I'm pulling my hair out.

If no one knows of anything, I might write an API description and 
propose it be included in Commons.  I'm hoping there is already a solution.

Thanks for any input.


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


Re: Runtime.exec() Utilities?

Posted by Lukas Bradley <lu...@somnia.com>.
> ANT gives you a selection of well-tested tasks of all kinds, combinable 
> and system-independent. Give it a try. HTH,

This looks like it might be perfect:

org.apache.tools.ant.taskdefs.Execute
Execute(ExecuteStreamHandler streamHandler, ExecuteWatchdog watchdog)

However, I don't see a stream handler that can batch input and output. 
In other words, I have a list of commands I want to send, and I just 
want all the output retrieved.   I was hoping one might be available, so 
I don't have to write my own in/out/err stream handlers.

Do you know of any?

I'm going to post a similar question to the ANT list.  I will repost the 
answer back here if a solution is received.


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


Re: Runtime.exec() Utilities?

Posted by Christian Aust <ch...@wilde-welt.de>.
Hi,

Lukas Bradley schrieb:
> Is there ANYTHING out there that can help manage executing system 
> commands to batch input, capture output, and generally not make a mess 
> of things on different platforms?
> 
> I'm pulling my hair out.
> 
> If no one knows of anything, I might write an API description and 
> propose it be included in Commons.  I'm hoping there is already a solution.
> 
> Thanks for any input.

I used to be quite successful adding ANT tasks to my code for system 
management. I.e. this code will copy files and subdirectories from one 
directory into another using ANTs copy-task. It will handle recursion as 
well as a list of patterns to exclude from copying.

import java.io.File;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;

/**
  * Copies ressources from the directory {@link #getResourceFile()}
  * into outputFile.
  *
  * @param outputFile target directory, must exist and be writeable
  * @throws ExportException
  */
private void copyRessourcesTo(File outputFile) throws ExportException {
    class CopyTask extends Copy {
       /**
        * Simple framework class to hold the task itself
        */
       public CopyTask() {
          Project p = new Project();
          p.init();
          setProject(p);
          setTaskName("copyResources");
          setTaskType("copyResources");
       }
    }

    CopyTask ct = new CopyTask();
    ct.setTodir(outputFile);
    FileSet fs = new FileSet();
    fs.setDir(getResourceFile());
    fs.setExcludes("*.vm");
    ct.addFileset(fs);
    ct.execute();
}

ANT gives you a selection of well-tested tasks of all kinds, combinable 
and system-independent. Give it a try. HTH,

-  Christian

-- 

Christian Aust
mailto:christian@wilde-welt.de
icq: 84500990 - Yahoo!: datenimperator - MSN: datenimperator
PGP: A94E 0181 664D 27E3 F05A  A751 6A7E 90D1 A0A3 DEC7

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