From: Andy Moreton <andrewjmoreton@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: execute shell scripts by call-process in msys2 environment
Date: Wed, 12 Sep 2018 17:45:35 +0100 [thread overview]
Message-ID: <vz136ued5qo.fsf@gmail.com> (raw)
In-Reply-To: 83y3c6lnl5.fsf@gnu.org
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)
next prev parent reply other threads:[~2018-09-12 16:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-12 9:32 execute shell scripts by call-process in msys2 environment holgar.sperr
2018-09-12 14:18 ` Eli Zaretskii
[not found] ` <mailman.675.1536761912.1284.help-gnu-emacs@gnu.org>
2018-09-12 14:57 ` holgar.sperr
2018-09-12 15:52 ` Eli Zaretskii
2018-09-12 16:45 ` Andy Moreton [this message]
2018-09-12 17:10 ` Eli Zaretskii
[not found] ` <mailman.691.1536772269.1284.help-gnu-emacs@gnu.org>
2018-09-13 8:57 ` holgar.sperr
[not found] ` <mailman.683.1536767585.1284.help-gnu-emacs@gnu.org>
2018-09-12 16:31 ` holgar.sperr
2018-09-12 17:03 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vz136ued5qo.fsf@gmail.com \
--to=andrewjmoreton@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).