title: How can I set the encoding of shell-command-on-region output?
body: <p>I have a small elisp script which applies Perl::Tidy on region or whole file. For reference, here's the script (borrowed from EmacsWiki):</p>
  
  <pre><code>(defun perltidy-command(start end)
  "The perltidy command we pass markers to."
  (shell-command-on-region start 
                         end 
                         "perltidy" 
                         t
                         t
                         (get-buffer-create "*Perltidy Output*")))
  
  (defun perltidy-dwim (arg)
  "Perltidy a region of the entire buffer"
  (interactive "P")
  (let ((point (point)) (start) (end))
  (if (and mark-active transient-mark-mode)
      (setq start (region-beginning)
            end (region-end))
    (setq start (point-min)
          end (point-max)))
  (perltidy-command start end)
  (goto-char point)))
  
  (global-set-key "\C-ct" 'perltidy-dwim)
  </code></pre>
  
  <p>I'm using current Emacs 23.1 for Windows (EmacsW32). The problem I'm having is that if I apply that script on a UTF-8 coded file ("U(Unix)" in the status bar) the output comes back Latin-1 coded, i.e. two or more characters for each non-ASCII source character.</p>
  
  <p>Is there any way I can fix that?</p>
  
  <p><strong>EDIT</strong>: Problem seems to be solved by using <code>(set-terminal-coding-system 'utf-8-unix)</code> in my <code>init.el</code>. In anyone has other solutions, go ahead and write them!</p>