If you use a UNIX shell (e.g., ksh, bash) along with NTEmacs, you've probably noticed that getting shell-command (M-!) and shell-command-on-region (M-|) to work properly with quoted arguments can be problematic. Even the variable win32-quote-process-args is documented to not completely solve the problem. Here's a complete solution. Put the below elisp into your .emacs file (or into a separate file and load that file from within .emacs), and you'll find that M-! and M-| work as expected. Even programmatic calls to shell-command and shell-command-on-region will work as expected. The only requirements are: o The shell named in shell-file-name must either be a full pathname, or it must be in your PATH. o The shell named in shell-file-name must allow this invocation syntax: shell pathname meaning to invoke shell and have it execute commands from pathname. All UNIX shells allow this, but cmd.exe does _not_, so this code doesn't work with cmd.exe as your shell. o You must have permission to create and delete files in the directory c:/temp. Send questions/comments to me. -- Francis Litterio PGP Key Fingerprint: franl@world.std.com 02 37 DF 6C 66 43 CD 2C http://world.std.com/~franl/ 10 C8 B5 8B 57 34 F3 21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Code to make shell-command and shell-command-on-region work ;; as expected with a UNIX shell under NTEmacs. ;; ;; Author: Francis Litterio, franl@world.std.com ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar my-shell-command-tmpfile "c:/temp/emacs1.tmp" "Pathname of temporary file used to hold the command supplied to my-shell-command.") (defvar my-shell-command-on-region-tmpfile "c:/temp/emacs2.tmp" "Pathname of temporary file used to hold the command supplied to my-shell-command-on-region.") (defun my-shell-prepare (tmpfile) "Called by my-shell-command and my-shell-command-on-region to prepare to spawn the command. This function uses dynamic scoping to change variables in its caller." (save-match-data (if (string-match "[ \t]*&[ \t]*$" command) (setq modified-command (substring command 0 (match-beginning 0)) real-command (concat real-command " &") background t))) (write-region (concat modified-command "\n") nil tmpfile) (message "")) (defun my-shell-cleanup (tmpfile background) "Called by my-shell-command and my-shell-command-on-region to cleanup after spawning the command." (if (not background) (condition-case nil (delete-file tmpfile) (error nil)))) (defun my-shell-command (command &optional output-buffer) "Drop in replacement for the standard Emacs shell-command. This one works under NT." (interactive "sShell command: ") (let ((modified-command command) (real-command my-shell-command-tmpfile) (background nil)) (my-shell-prepare my-shell-command-tmpfile) (prog1 (my-orig-shell-command real-command output-buffer) (my-shell-cleanup my-shell-command-tmpfile background)))) (defun my-shell-command-on-region (start end command &optional output-buffer replace) "Drop in replacement for the standard Emacs shell-command-on-region that works under NT." (interactive "r\nsShell command on region: ") (if (and (interactive-p) current-prefix-arg) (setq replace t)) (let ((modified-command command) (real-command my-shell-command-on-region-tmpfile) (background nil)) (my-shell-prepare my-shell-command-on-region-tmpfile) (prog1 (my-orig-shell-command-on-region start end real-command output-buffer replace) (my-shell-cleanup my-shell-command-on-region-tmpfile background)))) ;; Save the original function bindings. ;; (if (not (fboundp 'my-orig-shell-command)) (fset 'my-orig-shell-command (symbol-function 'shell-command))) (if (not (fboundp 'my-orig-shell-command-on-region)) (fset 'my-orig-shell-command-on-region (symbol-function 'shell-command-on-region))) ;; Install the wrapper function bindings. ;; (fset 'shell-command 'my-shell-command) (fset 'shell-command-on-region 'my-shell-command-on-region) I wrote: > If you use a UNIX shell (e.g., ksh, bash) along with NTEmacs, you've > probably noticed that getting shell-command (M-!) and > shell-command-on-region (M-|) to work properly with quoted arguments > can be problematic. Even the variable win32-quote-process-args is > documented to not completely solve the problem. My posting included code to make shell-command and shell-command-on-region work as expected. Well, there was one line missing: (setq shell-command-switch "-c") -- Francis Litterio PGP Key Fingerprint: franl@world.std.com 02 37 DF 6C 66 43 CD 2C http://world.std.com/~franl/ 10 C8 B5 8B 57 34 F3 21