從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>
它不適用於我的用例(請參閱修訂後的問題)。你可以在你的系統中測試我的Ant腳本,並讓我知道它的工作原理嗎? – 2012-01-09 10:27:27