Gnawk
Gnawk

Reputation: 355

how to write multiple exec arguments in ant

I want to write an ant script that will

  1. start up a new terminal
  2. Change user
  3. and run the Appium session

This is what i have so far but it doesn't do anything

    <exec executable="/bin/bash" os="${os.unix}" spawn="true">
        <arg value="-c" />
        <arg value="gnome-terminal su appium" />
        <arg value="appium &amp;" />
    </exec>

Upvotes: 2

Views: 4525

Answers (2)

David W.
David W.

Reputation: 107080

And what is the value of the property ${os.unix}? If you're going to use the os parameter, you usually give it a string constant and not a property value.

<exec executable="/bin/bash" os="unix" spawn="true">
    <arg value="-c" />
    <arg value="gnome-terminal su appium" />
    <arg value="appium &amp;" />
</exec>

This way, you could have an <exec> task for all Unix style operating systems, and another <exec> task for all the other ones (Windows).

Also understand the difference between <arg value="..."/> and <arg line="..."/>. I don't know the exact command structure for gnome-terminal, but when you pass something as a value, you're passing it as a single parameter -- even if it has spaces in it. For example:

<exec executable="foo">
   <arg value="-f foo -b bar"/>
</exec>

Will execute as if I typed this in the command line:

$ foo "-f foo -b bar"   # This is one command with one parameter. Note the quotation marks!

If I do this:

<exec executable="foo">
   <arg line="-f foo -b bar"/>
</exec>

Will execute as if I typed this in the command line:

$ foo -f foo -b bar # This is one command with four parameters

This is equivalent to the above Ant task:

<exec executable="foo">
   <arg value="-f"/>
   <arg value="foo"/>
   <arg value="-b"/>
   <arg value="bar"/>
</exec>

Currently, you're attempting to execute:

$ /bin/bash -c "gnome-terminal su appium" "appium &"

If this is what you want, fine. By the way, you could skip the whole /bin/bash stuff on Unix:

<exec executable="gnome-terminal" os="unix" spawn="true">
    <arg value="su appium"/>
    <arg value="appium &amp;"/>
</exec>

Upvotes: 7

Piotr Praszmo
Piotr Praszmo

Reputation: 18340

Try this:

<exec executable="/bin/bash" spawn="true" >
    <arg value="-c" />
    <arg value="x-terminal-emulator -e 'sudo -u appium appium'" />
</exec>

os="${os.unix}" seems incorrect, I've removed it completely.

-c and bash command needs to be in separate arg element.

su will start new shell. Use sudo with argument instead.

command passed to gnome-terminal needs to be quoted.

x-terminal-emulator should be more portable than gnome-terminal.


Actually, using bash doesn't seem to be necessary at all. Try:

<exec executable="x-terminal-emulator" spawn="true" >
    <arg value="-e" />
    <arg value="sudo -u appium appium" />
</exec>

Upvotes: 1

Related Questions