[Openmcl-devel] How to use lisp program in unix pipeline
Sven Van Caekenberghe
sven at beta9.be
Tue May 27 00:47:25 PDT 2003
On Wednesday, May 7, 2003, at 06:04 PM, Frank Sonnemans wrote:
> Hello all,
>
> I wrote a small lisp application which takes an xml file, filters it
> and
> writes a html file. What I now want to do is use this lisp application
> in
> several ways:
>
> Myfilter infile outfile
>
> Or
>
> Myfilter < infile > outfile
>
> Or
>
> Cat infile | Myfilter > outfile
>
> How do I do this with openmcl. As the startup time of openmcl is very
> short
> I would basically like to use it to replace my unreadable perl scripts.
>
> So far I got some results using a construct like:
>
> Cat Myfilter.lisp | openmcl -b
>
> Problem is that openmcl outputs it's welcome message and prompt before
> the
> output of my lisp program (see bottom of this message for example).
> This is
> unsuitable for the type of use I have in mind. Can I suppress the
> prompt and
> welcome message?
With my simple XML parser installed in ~/cvs/svc/xml I created the
following lisp code:
(load #p"home:cvs;svc;xml;xml")
(load #p"home:cvs;svc;xml;dom")
(load #p"home:cvs;svc;xml;lxml-dom")
(defun xml2lxml ()
(pprint (xml:parse-xml *standard-input* :output-type :lxml))
(terpri)
(finish-output *standard-output*)
(quit))
And saved it in a file called xml2lxml.lisp. With the following source
XML:
<!-- $Id: build.xml,v 1.1 2000/11/22 20:16:49 sven Exp $ -->
<!-- Ant 1.2 build file -->
<project name="SwingTest" default="jar" basedir=".">
<!-- set global properties for this build -->
<property name="src" value="${basedir}/src" />
<property name="build" value="${basedir}/bin" />
<target name="prepare">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
</target>
<target name="compile" depends="prepare">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" debug="on" />
</target>
<target name="copy-rsrc" depends="prepare">
<!-- Copy various resource files into ${build} -->
<copy todir="${build}">
<fileset
dir="${basedir}"
includes="images/*.gif" />
</copy>
</target>
<target name="jar" depends="compile,copy-rsrc">
<!-- Put everything in ${build} into the a ${name}.jar file -->
<jar
jarfile="${basedir}/SwingTest.jar"
basedir="${build}"
manifest="${basedir}/SwingTest.mf"/>
</target>
<target name="run" depends="compile,copy-rsrc">
<!-- Execute the main application -->
<java
classname="be.beta9.swingtest.SwingTest"
fork="yes"
classpath="${build}" />
</target>
<target name="clean">
<!-- Delete the ${build} directory trees -->
<delete dir="${build}" />
</target>
</project>
in a file called build.xml I can now do
[sven at voyager:~/tmp]$ cat build.xml | openmcl -l xml2lxml -e
'(xml2lxml)'
which produces the following LXML output and exits:
((:|project| :|name| "SwingTest" :|default| "jar" :|basedir| ".")
((:|property| :|name| "src" :|value| "${basedir}/src"))
((:|property| :|name| "build" :|value| "${basedir}/bin"))
((:|target| :|name| "prepare") :|tstamp| ((:|mkdir| :|dir|
"${build}")))
((:|target| :|name| "compile" :|depends| "prepare")
((:|javac| :|srcdir| "${src}" :|destdir| "${build}" :|debug| "on")))
((:|target| :|name| "copy-rsrc" :|depends| "prepare")
((:|copy| :|todir| "${build}")
((:|fileset| :|dir| "${basedir}" :|includes| "images/*.gif"))))
((:|target| :|name| "jar" :|depends| "compile,copy-rsrc")
((:|jar| :|jarfile| "${basedir}/SwingTest.jar" :|basedir| "${build}"
:|manifest| "${basedir}/SwingTest.mf")))
((:|target| :|name| "run" :|depends| "compile,copy-rsrc")
((:|java| :|classname| "be.beta9.swingtest.SwingTest" :|fork| "yes"
:|classpath| "${build}")))
((:|target| :|name| "clean") ((:|delete| :|dir| "${build}"))))
> Secondly how do I access the command line parameters from my lisp
> program?
In a previous post (the factorial command line example) I showed one,
simple way to do that (using a shell script to take the command line
arguments and push them in the -e expression).
HTH,
Sven
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel at clozure.com
http://clozure.com/cgi-bin/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list