Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would this command have exit code 1

Tags:

java

unix

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?

like image 372
Hughzi Avatar asked Oct 19 '25 14:10

Hughzi


1 Answers

@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!

like image 108
Hughzi Avatar answered Oct 21 '25 03:10

Hughzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!