Note that there are some explanatory texts on larger screens.

plurals
  1. POUnder Windows 7(cmd.exe), Is it possible to (print string) with GBK encoding in Clojure?
    text
    copied!<p>I was trying to print a Chinese String "哈哈" in clojure. The run-time environment is Windows 7, <code>cmd.exe</code>. The default code page is CP936(GBK). I can view GBK encoded source file under <code>cmd.exe</code> with "哈哈" displayed correctly, just by running <code>type core.clj</code>.</p> <p>I know I can change <code>cmd.exe</code>'s code page to 65001 to enable UTF-8, but I do want to know:</p> <ol> <li><strong>Is it stupid</strong> to try printing GBK characters under Win7 <code>cmd.exe</code> using a Java program?</li> <li><strong>Can I "generate" a string with GBK encoding in Clojure?</strong></li> </ol> <p>I used leiningen to setup project, and here is the <code>project.clj</code> file:</p> <pre class="lang-clj prettyprint-override"><code>(defproject fibo "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.5.1"]] :jvm-opts ["-Dfile.encoding=utf-8"] :main fibo.core) </code></pre> <p>The source code is simply:</p> <pre class="lang-clj prettyprint-override"><code>(ns fibo.core (:gen-class)) (defn -main [&amp; args] ;; work around dangerous default behaviour in Clojure (alter-var-root #'*read-eval* (constantly false)) (println "哈哈")) </code></pre> <p>The output looks like:</p> <pre><code>D:...\_dev\fibo&gt; lein run ???? </code></pre> <p>And I also tried to call <code>lein run</code> after setting JAVA_OPTION <strong>-Dfile.encoding=xxx</strong>. Unluckily, none of <strong>UTF-8 / GBK / GB18030 / ANSI / CP936</strong> helps, I always got <code>????</code>.</p> <p><strong>One thing to clarify</strong>: when I tried to use _JAVA_OPTION to change file.encoding, I didn't use <code>:jvm-opts ["-Dfile.encoding=utf-8"]</code> at the same time. After I tried all above encoding without luck, I added <code>:jvm-opts</code> in project.clj with UTF-8 as default encoding.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload