如何从Ant构建脚本执行交互式应用程序?

Hen*_*wan 6 ant console interactive exec task

来自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>
Run Code Online (Sandbox Code Playgroud)

使用ant运行时:

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

mysql:
Enter password:

BUILD SUCCESSFUL
Total time: 2 seconds
Run Code Online (Sandbox Code Playgroud)

输入密码后,立即退出.

将此与直接在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>
Run Code Online (Sandbox Code Playgroud)

man*_*_ak -1

我尝试过在 cosnole 上运行,如果你不分叉它就可以工作。正如文档中提到的。

除了 eclipse 之外,还有其他方法来配置 inputhandler。

正如这里所承认的那样。 http://www.coderanch.com/t/419646/tools/java-program-accept-user-input

完成这项工作的干净方法 http://www.myeclipseide.com/PNphpBB2-viewtopic-t-25337.html