Ant:i / o重定向“不得包含'<'字符”

时间:2015-05-12 21:52:42

标签: mysql ant

我想在build.xml文件中集成一个mysql语句用于ant。

命令应为:

var Image = Parse.Object.extend("Image");
var query = new Parse.Query(Image);
query.lessThan("number", 6); //Assumes a lowest index of 1; switch to 5 if your lowest index number is 0
query.include("collection");
query.find({
  success: function(results) {
    //Sort the results according to Collection, send to controllers, etc.
    //Each result will have a pulled, valid Collection object ready on its .collection
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});

对于ant,我定义了这个宏:

mysql -u$user -p$pwd -D$database < app/mysql/geo/data/geo.data.sql

首先,我尝试为每个参数使用多个<macrodef name="populateGeoDatabase"> <attribute name="user"/> <attribute name="password"/> <attribute name="database"/> <sequential> <exec executable="mysql"> <arg line="-u@{user} -p@{password} -D@{database} < app/mysql/geo/data/geo.data.sql" /> </exec> </sequential> </macrodef> - 行,也适用于 消耗输入-sql文件的i / o重定向。 两者都无法使用相同的错误消息:

'<arg value>'

如何实现“&lt;” - ant-exec的重定向?

更新

正如Bhavin Panchani指出的那样,我必须逃避“&lt;”与%lt;由于xml特定的标记:

The value of attribute "line" associated with an element type "arg" must not contain the '<' character.

但这也无法解决问题,但会导致运行的mysql-client停止打印所有有效的选项和变量:

        <exec executable="mysql">
            <arg line="-u@{user} -p@{password} -D@{database} &lt; app/mysql/geo/data/geo.data.sql" />
        </exec>

我唯一可以解决这个问题的方法是使用选项“-e”来执行sql语句,然后使用SOURCE。 此作品

 populate-dev-geo-database:
 [exec] mysql  Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64) using readline 6.2
 [exec] Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
 [exec] 
 [exec] Oracle is a registered trademark of Oracle Corporation and/or its
 [exec] affiliates. Other names may be trademarks of their respective
 [exec] owners.
 [exec] 
 [exec] Usage: mysql [OPTIONS] [database]
 [exec]   -?, --help          Display this help and exit.
 [exec]   -I, --help          Synonym for -?
 [exec]   --auto-rehash       Enable automatic rehashing. One doesn't need to use
 [exec] Variables (--variable-name=value)

 [exec] and boolean options {FALSE|TRUE}  Value (after reading options)
 [exec] --------------------------------- ----------------------------------------
 [exec] auto-rehash                       TRUE
 [exec] auto-vertical-output              FALSE

但是,我仍然对使用ant与mysql-client结合使用i / o重定向的解决方案感兴趣。

2 个答案:

答案 0 :(得分:2)

你需要逃避&lt;根据XML语法:

<exec executable="mysql">
            <arg line="-u@{user} -p@{password} -D@{database} &lt; app/mysql/geo/data/geo.data.sql" />
</exec>

答案 1 :(得分:1)

I / O重定向不会那样工作 - 这是你的shell所做的事情(至少在Unix上)。在Ant或<redirector>的{​​{1}}属性中使用<exec>

Ant的网站有几个专门针对此的常见问题解答,请参阅http://ant.apache.org/faq#shell-redirect-1