commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory" <ggreg...@seagullsoftware.com>
Subject RE: Runtime.exec() Utilities?
Date Wed, 30 Mar 2005 17:26:10 GMT
How about Commons-Launcher [1]?

Gary

[1] http://jakarta.apache.org/commons/launcher/

-----Original Message-----
From: Christian Aust [mailto:christian@wilde-welt.de] 
Sent: Wednesday, March 30, 2005 7:51 AM
To: Jakarta Commons Users List
Subject: Re: Runtime.exec() Utilities?

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



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


Mime
View raw message