help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: execute shell scripts by call-process in msys2 environment


From: Andy Moreton
Subject: Re: execute shell scripts by call-process in msys2 environment
Date: Wed, 12 Sep 2018 17:45:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt)

On Wed 12 Sep 2018, Eli Zaretskii wrote:

>> Date: Wed, 12 Sep 2018 07:57:32 -0700 (PDT)
>> From: holgar.sperr@gmail.com
>> 
>> > Do you really need to use the latest version of RCS offered by MSYS2?
>> 
>> No, but I thought on a solution within Emacs since 'shell-command' finds and
>> executes the shell script. Probably, this wouldn't be that easy.
>
> If shell-command finds and executes shell scripts, then what exactly
> is the problem you have?  Your original report said that cmd.exe runs
> the shell script, and that registering using 'ci' fails.  But if your
> Emacs can find and execute the shell scripts, then all of that should
> have worked, no?  What am I missing?

On MSYS2 "/usr/bin/ci" is a shell script that execs "rcs ci". This works
ok with `shell-command' as that shell can execute the script.

Other parts of emacs use `call-process' or `make-process', which expect
to run an executable directly, without invoking a shell. They can also
run shell scripts if the OS kernel execs the interpreter parsed from the
'#!' line in the script. MSYS2 (and Cygwin) run on Windows, which does
not do '#!' parsing in the kernel.

The following advice works for me on emacs 26 and later to fix this
problem on Cygwin (MSYS2 should be similar):

  (defun call-process:filter-args (args)
    "Ensure native Windows emacs can run Cygwin shell script programs."
    (let ((program (nth 0 args)))
      (if (executable-find program)
          args
        (list shell-file-name (nth 1 args) (nth 2 args) (nth 3 args)
              shell-command-switch
              (mapconcat #'shell-quote-argument
                         (append (list program) (nthcdr 4 args)) " ")))))
  (advice-add 'call-process :filter-args #'call-process:filter-args)

  (defun make-process:filter-args (args)
    "Ensure native Windows emacs can run Cygwin shell script programs."
    (let* ((command (plist-get args :command)))
      (if (executable-find (car command))
          args
        (plist-put args :command
                   (list shell-file-name shell-command-switch
                         (mapconcat #'shell-quote-argument command " "))))))
  (advice-add 'make-process :filter-args #'make-process:filter-args)








reply via email to

[Prev in Thread] Current Thread [Next in Thread]