2011-07-28 42 views
1

我一直在研究一個Python/Django項目,並且剛剛發現'./manage.py dbshel​​l'命令。它會讀取數據庫憑證的配置文件併爲您啓動數據庫shell。從ant任務打開數據庫shell?

在引擎蓋下,Django使用Python os.execvp(http://docs.python.org/library/os.html#os.execvp)函數。我無法像這樣在Java/Ant中找到任何東西,但我確實發現可以將正在運行的進程重定向到TTY(mysql>tty),但試圖爲此創建任務似乎不起作用。

<target name="test"> 
    <exec executable="/bin/sh"> 
     <arg value="-c" /> 
     <arg value="mysql -u foo -pbar &gt; `tty`" /> 
    </exec> 
</target> 

當我運行這個任務,我沒有得到一個數據庫外殼和一個名爲「不是tty」文件是在當前目錄中創建。

有沒有人有任何其他的想法,我怎麼可以從螞蟻啓動一個交互過程?

+0

execvp是execv的一部分( http://linux.about.com/library/cmd/blcmdl3_execv.htm)函數族。 – Toxygene

回答

2

不知道它會得到你一路有,但這裏的交互性開始:

<target name="get-inputs" depends="confirm-props"> 
    <input message="Enter your DB username:" addproperty="db.user.name" /> 
    <input message="Enter your DB password:" addproperty="db.user.password" /> 
    <input message="Enter DB Host:" addproperty="db.server" /> 
    ...call some other ant process... 
</target> 

這裏還有一個用於SQL調用:

<target name="db1"> 
    <sql 
     driver="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://${db.server}:3306/?useUnicode=true&amp;characterEncoding=UTF-8" 
     userid="name" 
     password="password" 
     classpathref="service.classpath" 
    > 
     <transaction> 
      <![CDATA[ 
      insert into foo (field1) values ('${foo-value}'); 
      ]]> 
     </transaction> 
    </sql> 
</target>