Message info
 
To:clojure@googlegroups.com From:Allen Johnson Subject:Re: why can i not shut-down my pc from Java? Date:Mon, 7 May 2012 17:05:54 -0400
 

The function passed to (defmulti) must take the same args as (defmethod).

Try this:

(defmulti halt
(fn [_ _]
(let [os (System/getProperty "os.name")]
(if (.startsWith os "Mac OS") :Linux (keyword os)))))

AJ

On Mon, May 7, 2012 at 4:53 PM, Jim - FooBar(); <jimpil1985@gmail.com> wrote:
> Following my earlier post, i tried converting the working shutdown
> function into a multi-method in order to make it cleaner to read... However
> for some reason the compiler is complaining and i can't pinpoint wheere the
> problem is! This is the multi-method:
> ------------------------------------------------------------------------------------------------------------------------------------
> (defmulti halt
> (fn []
> (let [os (System/getProperty "os.name")]
> (if (.startsWith os "Mac OS") :Linux (keyword os)))))
>
> (defmethod halt :Linux [root-pwd minutes-after]
> (clojure.java.shell/sh
> "sudo" "-S" "shutdown" (str "+" minutes-after) :in (str root-pwd "\n")))
>
> (defmethod halt :Windows [_ minutes-after]
> (clojure.java.shell/sh "shutdown" "-s" "-t" (str minutes-after)))
>
> (defmethod halt :Solaris [root-pwd seconds-after]
> (clojure.java.shell/sh "shutdown" "-S" "-y" (str "-g" seconds-after) "-i"
> "S" :in (str root-pwd "\n")))
>
> (defmethod halt :default [] (println "Unsupported operating system!"))
> -------------------------------------------------------------------------------------------------------------------------------------
>
> when calling (halt "some-password" 1) i'm getting this:
>
> java.lang.IllegalArgumentException: Wrong number of args (2) passed to:
> user$eval664$fn (NO_SOURCE_FILE:0)
>
> the same happens no matter how many args i pass in! this is very strange!
>
> thanks in advance...
>
> Jim
>
>
>
>
>
>
>
>
> On 07/05/12 19:52, Jim - FooBar(); wrote:
>
> Good stuff... :-)
>
> Jim
>
> On 07/05/12 19:51, Armando Blancas wrote:
>>
>> Can someone please verify that it works on windows as well???
>>
>
> It works on XP.
>
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
>
>
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en