Well, clojure.java.shell/sh did the trick...thanks for your time guys!
The correct function now is:
-----------------------------------------------------------------------------------
(defn shutdown-pc [root-pwd minutes-after]
(let [op-system (System/getProperty "os.name")]
(cond
(or (.startsWith op-system "Linux")
(.startsWith op-system "Mac OS"))
(clojure.java.shell/sh "sudo" "-S" "shutdown" (str "+"
minutes-after) :in (str root-pwd "\n"))
(.startsWith op-system "Windows")
(clojure.java.shell/sh "shutdown" "-s" "-t" (str
minutes-after))
:else (throw (RuntimeException. "Unsupported operating system!")))))
----------------------------------------------------------------------------------------------------
Notice the "\n" after the password string - it is needed otherwise it
won't accept it as correct!
Can someone please verify that it works on windows as well??? IT is
really hard for me to find a windows machine!
Thanks again...
Jim
On 07/05/12 16:32, Craig Brozefsky wrote:
"Jim - FooBar();"<jimpil1...@gmail.com> writes:
In preference to using Runtime/exec, you can use
clojure.java.shell/sh and write your password to the stdin of the
process using its :in argument.
Now that sounds more sensible but it means that the consumer has to
have clojure...what if i was to aot-compile the function with
gen-class to pretend it is plain Java?
The consumer would not need clojure, he is not suggesting you use some
clojure shell command, but rather the clojure.java.shell/sh function
which lets you write to stdin (and read stdout) from a shell process you
call from your Java program.
Also, you will need to invoke sudo with the -S argument so it reads from
stdin, and not from a pty.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en