0

i want to export variable from ant script, but i am doing something wrong cause I get error:

sh: 0: Can't open export DISPLAY=:10

There is fragment of my script

<target name="xvfb_start">
    <echo>Starting xvfb</echo>
    <exec executable="sh">
            <arg value="export DISPLAY=:10"/>
    </exec>
</target>

2 Answers 2

1

This doesn't work because sh expects the first argument to be a command to execute. export DISPLAY=:10 is no valid command (and since you pass this to sh as a single argument, it takes everything to be part of the script name to start, even the spaces and colon).

To make sh evaluate the arguments, try sh -c. That will give you a shell which has the variable DISPLAY defined. Since no further commands are on the command line, the shell will terminate and your variable will be lost with it.

Solutions:

  1. String all commands together
  2. Execute a script instead

For #1:

<exec executable="sh">
    <arg value="-c"/>
    <arg value="export DISPLAY=:10 ; xvfb"/>
</exec>

For #2, put all the commands into a normal shell script and have sh execute that.

Sign up to request clarification or add additional context in comments.

Comments

1

An approach I've found helpful is to export the variable in the same command as running ant.

For example (from your shell):

export DISPLAY=:10 ; ant your-target-name

It's also the case that any variables exported in your ~/.bashrc (if you have one) will be available to processes that ant runs. I have my export DISPLAY in there on my project. (If you're testing this, don't forget to call reset to get your terminal to pick up the changes to .bashrc).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.