2011-06-10 63 views
5

http://ant.apache.org/manual/Tasks/exec.html如何从Ant构建脚本执行交互式应用程序?

请注意,你不能用 叉形程序交互,只有这样,才能发送 输入是通过输入和 inputstring属性。还要注意,自从Ant 1.6以来, ,任何尝试读取分支程序中的 输入将 接收EOF(-1)。这是来自Ant 1.5的 ,其中这样的尝试 会阻止。

如何从蚂蚁启动交互式控制台程序并与之交互?

我想要做的是类似于drush sqlc功能,即启动mysql客户端解释器使用适当的数据库凭据,但不限于此用例。

下面是一个示例使用情况:

<project name="mysql"> 
    <target name="mysql"> 
    <exec executable="mysql"> 
     <arg line="-uroot -p"/> 
    </exec> 
    </target> 
</project> 

运行时使用蚂蚁:

$ ant -f mysql.xml mysql 
Buildfile: /home/ceefour/tmp/mysql.xml 

mysql: 
Enter password: 

BUILD SUCCESSFUL 
Total time: 2 seconds 

输入密码后,就立即退出。

这比较直接的外壳(预期的行为)执行时会发生什么:

$ mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 1122 
Server version: 5.1.58-1ubuntu1 (Ubuntu) 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 
This software comes with ABSOLUTELY NO WARRANTY. This is free software, 
and you are welcome to modify and redistribute it under the GPL v2 license 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> 

回答

0

我试图在cosnole运行,如果你不叉它的工作原理。 正如文档中提到的那样。

除了Eclipse之外,还有其他一些配置输入处理程序的方法。

正如此处所承认的。 http://www.coderanch.com/t/419646/tools/java-program-accept-user-input

一个干净的方式来得到这个工作 http://www.myeclipseide.com/PNphpBB2-viewtopic-t-25337.html

+0

它不适用于我的用例(请参阅修订后的问题)。你可以在你的系统中测试我的Ant脚本,并让我知道它的工作原理吗? – 2012-01-09 10:27:27

1

您可以通过shell启动您的命令,重定向标准输入/输出/错误的/到/于/dev/tty,对应于过程的controlling terminal

<target name="dbshell" description="Open a shell for interactive tasks"> 
    <exec executable="/bin/sh"> 
    <arg value="-c"/> 
    <arg value="mysql -u root -p &lt; /dev/tty &gt; /dev/tty 2&gt; /dev/tty"/> 
    </exec> 
</target>