Launching Appium on mac via PC using java SSH client

I’m trying to completely automate my iOS tests that run on Java using pc, on a remote Appium node running on mac.
I want my test to prepare his environment, so I want to restart the Appium server programmatically for each test.

When I execute on my mac terminal “appium --port 9191” it works great.
When I execute the same command manually with PuTTy it also works great.

But when I run the command using Java ssh clients nothing happens!
I tried using sshj and JSch, both doesn’t work.
(I was able to execute everything else on the mac using those APIs)

I also tried executing “/usr/local/bin/appium --port 9191” and “/Applications/ --port 9191”, didn’t work…

Please help, I’m out of ideas!

Hey Nir. What are the error messages you are getting? I

Hey Pavel.
I’m getting exit code 127 (command not found).
I also added appium to my PATH.

In my experience, when you invoke an SSH call to a remote machine you are not actually using the same PATH you configured using PuTTy. I solved this a few weeks ago but it was tricky. I’ll take a look in my solution later today and I’ll post the findings.
Cheers, Pavel

1 Like

Thanks! Looking forward for your solution.

Finally found the solution!
It appears the 127 not found error happened because of some dependency the Appium used and not the Appium itself.
Like Pavel said, they indeed did not use the same path.

The solution was to create a bash script containing:

appium --port 9191

And then launching the script using the java ssh client.


Ha! Awesome! Just came to post here…
That’s very similar to what I’ve done.
Also, don’t forget to kill the Appium server once you’re done with the test.
I do it with “killall node” but there’s probably a more humane way to close it.
Cheers, Pavel


I also want to start Appium via SSH, basically I can connect to the remote server and also run terminal commands. When I call ssh.sendCommand with :

“/Applications/ /Applications/ --command-timeout “7200” --debug-log-spacing --automation-name “Appium” --platform-name “Android” --platform-version “5.0.1” --app “/Users/qa/mobile/apps/test.apk” --full-reset”

it actually starts Appium as a process/service.

I do that by running that code:

public class SSHConnector {
    public String sendCommand(String command) throws IOException {
        SSHClient client = new SSHClient();
        String toReturn = "";
        client.connect("ip adress");
        try {
            client.authPassword("username", "password");
            Session session = client.startSession();
            try {
                Session.Command cmd = session.exec(command);
                cmd.join(10, TimeUnit.SECONDS);
                toReturn = cmd.getExitErrorMessage();
            } finally {
        } finally {
        return toReturn;

Directly after that I want to create an AndroidDriver, but I’m getting an error message that the connection is refused (from the remote server).

I think that’s happening because the session is closed and the client is disconnected ? I assume that Appium is killed on the remote server because the SSH connection is closed ? How can I keep Appium running although the SSH connection is closed ?



I figured out a pretty nice solution for folks that actually don’t run Appium on the same machine as the CI - using SSH and tmux. That works from code as well as from the CI, Bamboo in my case.

Anyone interested in a small blog post about it ?

1 Like

Absolutely. I’m sure many would benefit from reading something like that.

I hope that’s interesting for some folks:

Thanks a million @nir_soluto,

Your solution worked for me after a day of failed attempts to solve it.

My hat`s off to you sir.

I tried your blog post but still getting errors on not finding ADB , It cannot detect ANDROID_HOME.

Can you be specific on where your setting the path to ANDROID SDK. Is it in the same session.

Example code will be great help.