Java Process, waitFor gives me a 255 exitCode calling a sh file
<p>I have a process which should reboot a client from a server.</p>

<p>From my java webapp i reach a controller on the local server</p>

<pre><code>@RequestMapping(value = "/client/restart", method = RequestMethod.GET)
    public int restartClient(@RequestParam(value = "idClient") int idClient) {
        Client client = clientService.findById(idClient);
        int numeroClient = client.getNumeroClient();
        String command = "/home/pi/park/script/resetClient.sh";
        int exitCode = 1;
        try {
            Process p = new ProcessBuilder(command, "" + numeroClient).start();

            p.waitFor();
            logger.debug("wait for esce con: "+p.waitFor());
            exitCode = p.exitValue();

        } catch (InterruptedException | IOException e) {

            logger.error("I/O", e);
        }

        return exitCode;

    }
</code></pre>

<p>this should return the exitCode of the operation. If i call <code>resetClient.sh</code>directly from the shell, with its argument, the client gets rebooted correctly.</p>

<p>resetClient.sh it's a simple:</p>

<pre><code>#!/bin/sh

CLIENT=$1

ssh client$CLIENT 'sudo /etc/init.d/myscript restart'
</code></pre>

<p>I have a no password access via ssh between the server and the clients.
My logger returns me <code>p.waitFor() = 255</code>
I've tried with command absolute path or relative, but it's the same
If I run the .sh command from the server shell, i get correctly 0</p>