On Mon, May 7, 2012 at 11:08 AM, Jim - FooBar(); <jimpil1...@gmail.com>wrote:

> Hello everyone,
>
> I was just messing about with the following function and cannot figure out
> why it won't work...
> I know that the command I'm passing to the runtime object is a valid unix
> command...i can execute it on my terminal no problem! Java however refuses
> send the "halt" signal to my ubuntu shell...any ideas?
> ------------------------------**------------------------------**
> ------------------------------**------------------------------**---------
> (defn shutdown-pc [root-pwd minutes-after]
> (let [op-system  (System/getProperty "os.name")
>      enviroment (Runtime/getRuntime)]
> (cond
>    (or (.startsWith op-system "Linux")
>        (.startsWith op-system "Mac OS"))
>             (.exec enviroment (str "echo " root-pwd " |" " sudo -S
> shutdown -h +" minutes-after))
>


I think input redirection (the "|" you have there) is a construct of your
shell rather than the OS, so you have to wrap that in a call to bash or
whatever shell you prefer.

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.

Another alternative might be to configure your /etc/sudoers to not require
a password when running the shutdown command for the user that is making
this call.

--Aaron

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

Reply via email to