Hughzi
Hughzi

Reputation: 2580

Why would this command have exit code 1

I am relatively new to UNIX and have a requirement to set the date/time on a server from a .jar file.

I have tried the following:

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.Process p = rt.exec("sudo date --set=\"Tue Aug 11 10:10:20 BST 2015\"");
        p.waitFor();

        logger.warn("exit code:  " + p.exitValue());

The exit code is = 1, which apparently is a "general error". I have been able to run commands requiring sudo successfully in this way.

any thoughts?

Upvotes: 4

Views: 7559

Answers (1)

Hughzi
Hughzi

Reputation: 2580

@Veselin may be interested also:

The problem was date is a shell command and i needed access to the shell - I have root access already the amended command is:

    java.lang.Process p = rt.exec(new String[] {"/bin/sh", "-c","sudo date --set=\"Tue Aug 11 10:10:20 BST 2015\""});

Hope this helps someone!

Upvotes: 3

Related Questions