2

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>

2 Answers 2

7

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Nice one. Helpful !
1

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>

5 Comments

Hi I tried doing this since i dont have x-terminal-emulator but when i run it, it does something and close the terminal right away. <exec executable="gnome-terminal" spawn="true" > <arg value="-e" /> <arg value="sudo -u appium appium" /> </exec>. Also, where can i put in the command appium & in order to start appium?
If you use appium& instead of appium, your terminal will start appium in background and close right away. Try executing sudo -u appium appium in your current terminal and see why it's not working correctly.
Try absolute path to appium e.g: sudo -u appium /something/bin/appium. Or, add -i option: sudo -iu appium appium
ok with this <exec executable="/bin/bash" os="${os.unix}" spawn="true" > <arg value="-c" /> <arg value="gnome-terminal -x su appium" /> <arg value="appium" /> </exec> it starts up new terminal with changed user but it doesn't run "appium"
su appium will start a new shell. Next command can be executed only after that shell is closed. Use sudo as I described or su with -c option to execute appium instead of shell.

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.