来自http://ant.apache.org/manual/Tasks/exec.html:
请注意,您无法与分叉的程序交互,发送输入的唯一方法是通过input和inputstring属性。此外,请注意自Ant 1.6以来,任何尝试在分叉的程序中读取输入的尝试都将收到EOF(-1)。这是从Ant 1.5开始的更改,早期尝试会被阻塞。
如何从Ant启动并与交互式控制台程序交互?
我想要做的类似于drush sqlc功能,即使用正确的数据库凭据启动mysql客户端解释器,但不仅限于此用例。
这里是一个示例用例:
<project name="mysql">
<target name="mysql">
<exec executable="mysql">
<arg line="-uroot -p"/>
</exec>
</target>
</project>
使用ant运行时:
$ ant -f mysql.xml mysql
Buildfile: /home/ceefour/tmp/mysql.xml
mysql:
Enter password:
BUILD SUCCESSFUL
Total time: 2 seconds
输入密码后,程序立即退出。
与在Shell上直接执行的情况进行比较(预期行为):
$ 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>