ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastien Blanc <Sebastien.Bl...@alcatel.com>
Subject Re: launch interpreter
Date Wed, 04 Jun 2003 18:10:54 GMT
if anybody interested, I got it working with the interactive console
seb.

 <target name="jython-stubs">
  <available property="jython.present"
classname="org.python.util.PythonInterpreter"/>
  <antcall target="checkJython" />
  <script language="jpython"> <![CDATA[
from org.python.core import *;
from org.python.util import *;

from java.lang import String
from java.lang import System
from java.lang import Throwable;

import jarray;

print 'Running Jython... '

dummy = jarray.zeros(0, String);

System.setProperty("python.security.respectJavaAccessibility", "0")
#PySystemState.initialize(System.getProperties(), System.getProperties(), dummy)

# Create the interpreter.
interp = InteractiveConsole()
mod = imp.addModule("__main__")
interp.setLocals(mod.__dict__)

jythonFileName = "tststubs.py" #Config.getProperty("ems.jython")
#if ((jythonFileName != null)&&(jythonFileName.length()!=0)) {
try:
    print 'Processing initial file' + jythonFileName
    #interp.execfile(jythonFileName)
except Throwable, e:
    Py.printException(e)
    print 'Error processing ' + jythonFileName + ': ' + e.toString()

Py.getSystemState().path.insert(0, PyString(""))

try:
    print 'Running in interactive mode'
    interp.interact(None);
except Throwable, e:
    Py.printException(e)
    print 'Error starting python interpretor: ' +  e.toString()
]]> </script>
   </target>

Tim Gordon wrote:

> You'd have to talk to someone who knows what BSFManager.execute does -
> people have often posted interactive examples written in JavaScript, so
> console I/O can obviously be directed to code hosted in script.
>
> The reason you can't use Java and Exec is that the stream handler doesn't
> connect the console input from ANT to the spawned Process (at least it
> didn't used to - it looks like it might be fixed in 1.6).
>
> -----Original Message-----
> From: sblanc@usa.alcatel.com [mailto:sblanc@usa.alcatel.com]On Behalf Of
> Sebastien Blanc
> Sent: 04 June 2003 14:52
> To: Ant Users List
> Subject: Re: launch interpreter
>
> Hi !
> I was just wondering if this was possible w/ ANT; for instance a java
> program
> can do it (i.e. embbed a jython prompt, the interactive console taking care
> of
> the i/o reading and interpreting). something like:
> PySystemState.initialize(System.getProperties(), System.getProperties(), new
> String[0]);
> // Create the interpreter.
> InteractiveConsole interp = new InteractiveConsole();
> I'll try launching the same with BSF jython and see what's possible: is a
> new
> thread launch when launchin <script> or not (I guess it wd be better if not
> in
> that case) ?
> seb.
>
> Tim Gordon wrote:
>
> > I think you may be on to a hiding to nothing here
> >
> > - ANT will wait for forked JVMs and Exec'd processes to complete before
> ANT
> > will contiunue with the next task
> > - Even if you had a Spawn task that would let the spawned process run
> async
> > how exactly are you going to maintain in input output streams to your
> > spawned process after the launching JVM exits? Have a good read of the
> > javadoc for java.lang.Process... You can only really get away with
> spawning
> > form ANT if your i/o doesn't come from console.
> >
> > -----Original Message-----
> > From: Sebastien Blanc [mailto:Sebastien.Blanc@alcatel.com]
> > Sent: 04 June 2003 01:05
> > To: user@ant.apache.org
> > Subject: launch interpreter
> >
> > Hello !
> > I'm trying to do a startup script with ANT that would launch the jython
> > prompt so that the user can launch jython methods when wanted.
> > I use the following:
> > <java classname="org.python.util.jython"
> > argline="-Dpython.home=${vendor.jython.home}
> > -Dpython.cachedir=${vendor.jython.cachedir}" >
> >              <classpath refid="process.run.classpath"/>
> > </java>
> > and get the following exception:
> > java.lang.NullPointerException
> >         at java.io.StringReader.<init>(StringReader.java:33)
> >         at org.apache.tools.ant.DefaultLogger.messageLogged(DefaultLogge
> >
> >         at org.apache.tools.ant.Project.fireMessageLoggedEvent(Project.j
> >
> >         at org.apache.tools.ant.Project.fireMessageLogged(Project.java:2
> >
> >         at org.apache.tools.ant.Project.log(Project.java:394)
> >         at org.apache.tools.ant.Task.log(Task.java:302)
> >         at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:180)
> >
> >         at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
> >         at org.apache.tools.ant.Task.perform(Task.java:319)
> >         at org.apache.tools.ant.Target.execute(Target.java:309)
> >         at org.apache.tools.ant.Target.performTasks(Target.java:336)
> >         at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
> >
> >         at org.apache.tools.ant.Project.executeTargets(Project.java:1250
> >
> >         at org.apache.tools.ant.Main.runBuild(Main.java:610)
> >         at org.apache.tools.ant.Main.start(Main.java:196)
> >         at org.apache.tools.ant.Main.main(Main.java:235)
> > if I use fork="true", the jvm hangs and Ctrl+C triggers the prompt (but
> > then exit the ANT JVM).
> > is there a way to get the jython interpreter (scripting ? parallel ?).
> > I'd guess any interpreter launching would lead to the same issue (I know
> > that the DOS one for instance wd use exec but I don't see any portable
> > equivalent here).
> > thanx for help,
> > seb.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message