0

I've been trying to convert a command I run in bash to start a resque consumer using Phing but I couldn't find a way to set environment variables before exec the php command.

This is the command I'm trying to convert:

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

I've tried:

<!-- 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>

And:

<!-- 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>

Any idea how can I make this work? Is it even possible to set environment variables using Phing?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
mjsilva
  • 1,327
  • 3
  • 13
  • 21
  • possible duplicate of [Phing exec command to set environment variable](http://stackoverflow.com/questions/5804817/phing-exec-command-to-set-environment-variable) – shanethehat Jan 06 '14 at 09:05
  • I think you're right @shanethehat. And unfortunately to me that means there's no way to achieve this :( – mjsilva Jan 06 '14 at 09:26
  • You could just make different properties files containing those environmental variable values, make sure not to track them in your version control. Then each environment just has its own properties files. Doesn't answer your question, but gets a similar result depending on your particular need. – eddiemoya Mar 13 '14 at 22:15

2 Answers2

0

Use env command before your script.

<!-- 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>
user1046885
  • 171
  • 2
  • 7
-1

Try with this:

<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>
cernio
  • 304
  • 2
  • 7
  • 3
    I get ```phing.tasks.system.ExecTask doesn't support the 'env' creator/adder```. The ```env``` tag does not exist, confirmed by the documentation : http://www.phing.info/docs/guide/trunk/apbs14.html – Ugo Méda Oct 07 '14 at 12:47