2014-01-06 49 views
0

我一直在嘗試轉換命令,我在bash中運行以啓動使用Phing的resque使用者,但我找不到在執行php之前設置環境變量的方法命令。如何在運行Phing目標命令之前設置環境變量

這是我想要轉換的命令:

APPLICATION_ENV=dev VVERBOSE=1 QUEUE=myqueue APP_INCLUDE=app/cli/bootstrap.php php composer/chrisboulton/php-resque/resque.php 

我已經試過:

<!-- Resque start consumer --> 
<target name="start_resque_consumer" description="Spans a resque consumer"> 
    <property environment="APPLICATION_ENV" value="dev"/> 
    <property environment="VVERBOSE" value="1"/> 
    <property environment="QUEUE" value="myqueue"/> 
    <property environment="APP_INCLUDE" value="${project.basedir}/app/cli/bootstrap.php"/> 
    <exec executable="php" checkreturn="true" passthru="true" dir="${project.basedir}/composer/chrisboulton/php-resque"> 
     <arg line="resque.php"/> 
    </exec> 
</target> 

和:

<!-- Resque start consumer --> 
<target name="start_resque_consumer" description="Spans a resque consumer"> 
    <exec executable="APPLICATION_ENV=dev 
         VVERBOSE=1 
         QUEUE=myqueue 
         APP_INCLUDE=${project.basedir}/app/cli/bootstrap.php 
         php" checkreturn="true" passthru="true" dir="${project.basedir}/composer/chrisboulton/php-resque"> 
     <arg line="resque.php"/> 
    </exec> 
</target> 

任何想法,我怎麼能做出這種工作?甚至有可能使用Phing設置環境變量?

+0

可能重複(http://stackoverflow.com/questions/5804817/phing-exec-command-to-set-environment-variable) – shanethehat

+0

我想你」再右邊@shanethehat。不幸的是,對我來說,這意味着沒有辦法達到這個目的:( – mjsilva

+0

)你可以製作包含這些環境變量值的不同屬性文件,不要在你的版本控制中跟蹤它們,然後每個環境都有自己的屬性文件。 't回答你的問題,但得到了類似的結果,這取決於你的特定需求。 – eddiemoya

回答

-1

嘗試用這樣的:你的腳本之前

<target name="start_resque_consumer" description="Spans a resque consumer"> 
    <exec executable="php" checkreturn="true" passthru="true" dir="${project.basedir}/composer/chrisboulton/php-resque"> 
     <arg value="${project.basedir}/composer/chrisboulton/php-resque/resque.php" /> 
     <env key="VVERBOSE" value="1" /> 
     <env key="QUEUE" value="myqueue" /> 
     <env key="APP_INCLUDE" value="${project.basedir}/app/cli/bootstrap.php" /> 
    </exec> 
</target> 
+3

我得到'''phing.tasks.system.ExecTask不支持'env'創建者/加法器'''env '''標記不存在,由文檔證實:http://www.phing.info/docs/guide/trunk/apbs14.html –

0

使用env命令。

<!-- Here are the initial data, under .gitignore --> 
<property file="build/secret/local.ini"/> 
<!-- Let's create some shortcuts --> 
<property name="local.mysql.connect" value="-h${local.mysql.host} -P${local.mysql.port} -u${local.mysql.user}"/> 
<property name="local.mysql.env" value="env MYSQL_PWD=${local.mysql.password}"/> 

<target name="some_target"> 
    <!-- Tens of them. "The password in command line" warning finally silenced. It can be put in cron ! --> 
    <exec 
     command="${local.mysql.env} mysql ${local.mysql.connect} ${local.mysql.database.target} &lt; ./sql/some_script.sql" 
    /> 
</target> 
[Phing exec命令來設置環境變量]的
相關問題