This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: output of the 'system'
- To: kawa at sourceware dot cygnus dot com
- Subject: Re: output of the 'system'
- From: Jim White <jim at pagesmiths dot com>
- Date: Fri, 14 Sep 2001 09:34:46 -0700
At 01:20 PM 9/11/2001 -0700, Valentyn Kamyshenko wrote:
>is there a way to capture output of the `system' call in kawa?
>(that is, I'd like to get the listing of the current directory in the
>call
> (system "ls -l"))
You could use Ant as a library for that. This code snippet invokes the
"ant" task, but you could use the "exec" task instead.
http://jakarta.apache.org/ant/index.html
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Ant;
// import org.apache.tools.ant.taskdefs.ExecTask;
...
final Project project = new Project();
project.init();
final BuildLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(getOutputLevel());
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
logger.setEmacsMode(getEmacsMode());
project.addBuildListener(logger);
// project.fireBuildStarted();
// This would be where to start changing to exec for "system".
// final ExecTask execTask = (ExecTask) project.createTask("exec");
// The parameters are different than the Ant task of course.
final Ant antTask = (Ant) project.createTask("ant");
antTask.setDir(new File(projectPath));
if
(!org.apache.tools.ant.Main.DEFAULT_BUILD_FILENAME.equals(getBuildFileName()))
{
antTask.setAntfile(getBuildFileName());
}
if (target != null)
antTask.setTarget(target);
Throwable error = null;
try {
antTask.execute();
} catch(RuntimeException exc) {
error = exc;
throw exc;
} catch(Error err) {
error = err;
throw err;
} finally {
// project.fireBuildFinished(error);
}
jim
----------------------------------------------------------------
James P. White Netscape DevEdge Champion for IFC
IFC Exchange * Insanely great Java * http://www.ifcx.org
jim@pagesmiths.com Pagesmiths' home is http://www.pagesmiths.com