views:

136

answers:

1

I'm trying to start a server as part of an Ant artifact.

Here are the relevant lines:

    <exec dir="." executable="cmd.exe" spawn="true">
        <arg line="/c c:\Java\james-2.3.2\bin\debug.bat" />
    </exec>

If I start it with ant from the command line, a process is spawned and I get a command prompt and everything seems fine. However, if I start it from IntelliJ 6, my IDE, the build stays alive until I kill the server.

Here's the line IntelliJ uses to start ant:

C:\Java\jdk1.6.0_02\bin\java -Xmx128m -Dant.home=C:\Java\apache-ant-1.7.1 -Dfile.encoding=UTF-8 -classpath "C:\Java\apache-ant-1.7.1\lib\ant-antlr.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-bcel.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-bsf.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-log4j.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-oro.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-regexp.jar;C:\Java\apache-ant-1.7.1\lib\ant-apache-resolver.jar;C:\Java\apache-ant-1.7.1\lib\ant-commons-logging.jar;C:\Java\apache-ant-1.7.1\lib\ant-commons-net.jar;C:\Java\apache-ant-1.7.1\lib\ant-jai.jar;C:\Java\apache-ant-1.7.1\lib\ant-javamail.jar;C:\Java\apache-ant-1.7.1\lib\ant-jdepend.jar;C:\Java\apache-ant-1.7.1\lib\ant-jmf.jar;C:\Java\apache-ant-1.7.1\lib\ant-jsch.jar;C:\Java\apache-ant-1.7.1\lib\ant-junit.jar;C:\Java\apache-ant-1.7.1\lib\ant-launcher.jar;C:\Java\apache-ant-1.7.1\lib\ant-netrexx.jar;C:\Java\apache-ant-1.7.1\lib\ant-nodeps.jar;C:\Java\apache-ant-1.7.1\lib\ant-starteam.jar;C:\Java\apache-ant-1.7.1\lib\ant-stylebook.jar;C:\Java\apache-ant-1.7.1\lib\ant-swing.jar;C:\Java\apache-ant-1.7.1\lib\ant-testutil.jar;C:\Java\apache-ant-1.7.1\lib\ant-trax.jar;C:\Java\apache-ant-1.7.1\lib\ant-weblogic.jar;C:\Java\apache-ant-1.7.1\lib\ant.jar;C:\Java\apache-ant-1.7.1\lib\xercesImpl.jar;C:\Java\apache-ant-1.7.1\lib\xml-apis.jar;C:\Java\jdk1.6.0_02\lib\tools.jar;C:\Program Files\JetBrains\IntelliJ IDEA 6.0\lib\idea_rt.jar" com.intellij.rt.ant.execution.AntMain2 -logger com.intellij.rt.ant.execution.IdeaAntLogger2 -inputhandler com.intellij.rt.ant.execution.IdeaInputHandler -buildfile C:\Java\Projects\CcMailer\ccmailer.xml jar

I suspect the inputhandler parameter has something to do with the problem, but if I run it myself the problem is not reproduced. Either way, I have only limited control over what IntelliJ does.

My question is: how does IntelliJ even know the process is running? The Ant process is long gone. Is there a way to start a subprocess in a more sneaky way, so that IntelliJ won't even know there's anything to wait around for?

Here's what I've tried so far: I tried using the start command, like this:

    <exec dir="." executable="cmd.exe" spawn="true">
        <arg line="/c start cmd /c c:\Java\james-2.3.2\bin\debug.bat" />
    </exec>

I also tried using python, with code like this:

import os.path
import subprocess
subprocess.Popen(["cmd.exe", "/c", "debug.bat"], stdin=open(os.path.devnull), stdout=open(os.path.devnull, "w"), stderr=subprocess.STDOUT)

To no avail. The build window always stays up until I kill the server.

Any ideas?

A: 

I've given up on figuring this out, so instead I set up an XML RPC server that does the starting and stopping, and the startup/shutdown scripts make an XML RPC call.

Code for the server (simplified):

from __future__ import with_statement

from threading import Lock
from SimpleXMLRPCServer import SimpleXMLRPCServer

server = SimpleXMLRPCServer(("localhost", 8000), allow_none=True)
server.register_introspection_functions()

class JamesController(object):
    def __init__(self):
        self.lock = Lock()
        self.started = False

    def start(self):
        # starting code using subprocess

    def stop(self):
        # stopping code


server.register_instance(JamesController())
server.serve_forever()

And then the start/stop scripts become something like:

import xmlrpclib

s = xmlrpclib.Server('http://localhost:8000')
s.start()

It's clunky, and requires some time.sleep() calls sprinkled, but it gets the job done.

itsadok