【发布时间】:2011-09-12 07:16:13
【问题描述】:
来自http://ant.apache.org/manual/Tasks/exec.html:
请注意,您无法与 分叉程序,唯一的发送方式 输入是通过输入和 输入字符串属性。另请注意 从 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>
【问题讨论】:
标签: ant console exec task interactive