2011-06-10 29 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> 
相關問題