开发者

Open a database shell from ant task?

I've been working on a Python/Django project and I just discovered the './manage.py dbshell' command. It reads your configuration file for the database credentials and launches a database shell开发者_开发技巧 for you.

Under the hood, Django uses the Python os.execvp (http://docs.python.org/library/os.html#os.execvp) function. I wasn't able to find anything in Java/Ant like this, but I did discover that you can redirect a running process to your TTY (mysql > tty), but trying to create an task for this doesn't seem to work.

<target name="test">
    <exec executable="/bin/sh">
        <arg value="-c" />
        <arg value="mysql -u foo -pbar &gt; `tty`" />
    </exec>
</target>

When I run this task, I don't get a database shell and a file called "not a tty" is created in the current directory.

Does anyone have any other ideas on how I could launch an interactive process from ant?


Not sure its going to get you all the way there, but here's a start for interactivity:

<target name="get-inputs" depends="confirm-props">
    <input message="Enter your DB username:" addproperty="db.user.name" />
    <input message="Enter your DB password:" addproperty="db.user.password" />
    <input message="Enter DB Host:" addproperty="db.server" />
    ...call some other ant process...
</target>

And here's one for SQL calls:

<target name="db1">
    <sql
        driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://${db.server}:3306/?useUnicode=true&amp;characterEncoding=UTF-8"
        userid="name"
        password="password"
        classpathref="service.classpath"
    >
        <transaction>
            <![CDATA[
            insert into foo (field1) values ('${foo-value}');
            ]]>
        </transaction>
    </sql>
</target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜