unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* execute shell scripts by call-process in msys2 environment
@ 2018-09-12  9:32 holgar.sperr
  2018-09-12 14:18 ` Eli Zaretskii
       [not found] ` <mailman.675.1536761912.1284.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: holgar.sperr @ 2018-09-12  9:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I wanted to activate version control from within Emacs (26.1 under msys2) using the rcs backend provided through msys2 repository.

The problem is now that for instance the registering by 'ci' is not successful, because the corresponding shell script is not found.

What I do understand by now: Processes in this setup are initialized by 'cmd.exe'.

Is there an easy solution to circumvent this problem?

Or would you recommend a different setup, e.g. ezwinports? What should be considered in this case?

(I do like msys2 for scripting and easy administration and would therefore prefer a msys2 solution.)

Thanks for any help,
Holger


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
  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>
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2018-09-12 14:18 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 12 Sep 2018 02:32:46 -0700 (PDT)
> From: holgar.sperr@gmail.com
> Injection-Date: Wed, 12 Sep 2018 09:32:46 +0000
> 
> I wanted to activate version control from within Emacs (26.1 under msys2) using the rcs backend provided through msys2 repository.
> 
> The problem is now that for instance the registering by 'ci' is not successful, because the corresponding shell script is not found.
> 
> What I do understand by now: Processes in this setup are initialized by 'cmd.exe'.
> 
> Is there an easy solution to circumvent this problem?

Do you really need to use the latest version of RCS offered by MSYS2?

> Or would you recommend a different setup, e.g. ezwinports?

Naturally, that's what I would recommend ;-)  I'm still using the
ported RCS available there for some very old repositories.

> What should be considered in this case?

Nothing; those ports are native Windows ports and will work with a
native Windows Emacs without any problems.  They do for me.

> (I do like msys2 for scripting and easy administration and would therefore prefer a msys2 solution.)

Well, you have just bumped into one problem with MSYS2 solutions.  In
general, if you want to use MSYS2, you should have most or all of your
programs be MSYS2 builds, not MinGW (a.k.a. "native") builds.

OTOH, the ezwinports port of RCS should run from MSYS2 shells without
problems.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
       [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
       [not found]     ` <mailman.683.1536767585.1284.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: holgar.sperr @ 2018-09-12 14:57 UTC (permalink / raw)
  To: help-gnu-emacs

Am Mittwoch, 12. September 2018 16:18:35 UTC+2 schrieb Eli Zaretskii:

[...]

>> What I do understand by now: Processes in this setup are initialized by 
>> 'cmd.exe'.
>> 
>> Is there an easy solution to circumvent this problem?
> 
> 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.
 
>> Or would you recommend a different setup, e.g. ezwinports?
> 
> Naturally, that's what I would recommend ;-)  I'm still using the
> ported RCS available there for some very old repositories.
> 
>> What should be considered in this case?
> 
> Nothing; those ports are native Windows ports and will work with a
> native Windows Emacs without any problems.  They do for me.
> 
>> (I do like msys2 for scripting and easy administration and would therefore 
>> prefer a msys2 solution.)
> 
> Well, you have just bumped into one problem with MSYS2 solutions.  In
> general, if you want to use MSYS2, you should have most or all of your
> programs be MSYS2 builds, not MinGW (a.k.a. "native") builds.
> 
> OTOH, the ezwinports port of RCS should run from MSYS2 shells without
> problems.

I will try the outside-emacs-solution you are suggesting (especially the last mentioned possibility).

Thank you for your advice.
Holger


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
  2018-09-12 14:57   ` holgar.sperr
@ 2018-09-12 15:52     ` Eli Zaretskii
  2018-09-12 16:45       ` Andy Moreton
       [not found]     ` <mailman.683.1536767585.1284.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2018-09-12 15:52 UTC (permalink / raw)
  To: help-gnu-emacs

> 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?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
       [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
  0 siblings, 1 reply; 9+ messages in thread
From: holgar.sperr @ 2018-09-12 16:31 UTC (permalink / raw)
  To: help-gnu-emacs

Am Mittwoch, 12. September 2018 17:53:08 UTC+2 schrieb Eli Zaretskii:
>>> 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?

C-x v v initializes a process: (call-process ...) which leads to an error.

      apply: Searching for program: No such file or directory, ci

Doing M-! (shell-command) finds the script 'ci' of the msys2 installation
and returns the same output as called from mingw64 shell.

('exec-path' contains the relevant directory.)

Sorry for not providing the full information from the beginning. Hope this
makes it clearer and explains, why I assumed an emacs-solution.

Thanks again.
Holger


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
  2018-09-12 15:52     ` Eli Zaretskii
@ 2018-09-12 16:45       ` Andy Moreton
  2018-09-12 17:10         ` Eli Zaretskii
       [not found]         ` <mailman.691.1536772269.1284.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Andy Moreton @ 2018-09-12 16:45 UTC (permalink / raw)
  To: help-gnu-emacs

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)








^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
  2018-09-12 16:31       ` holgar.sperr
@ 2018-09-12 17:03         ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2018-09-12 17:03 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 12 Sep 2018 09:31:52 -0700 (PDT)
> From: holgar.sperr@gmail.com
> 
> C-x v v initializes a process: (call-process ...) which leads to an error.
> 
>       apply: Searching for program: No such file or directory, ci
> 
> Doing M-! (shell-command) finds the script 'ci' of the msys2 installation
> and returns the same output as called from mingw64 shell.
> 
> ('exec-path' contains the relevant directory.)

OK, thanks.  On Unix, call-process is capable of running shell
scripts, but Windows doesn't know how to do that based on the #!
signature of the script.  So it doesn't work out of the box.

However, you could write a simple 'ci.bat' batch file that executes
the same command as the 'ci' the shell script, then it should work
without the need to involve Bash.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
  2018-09-12 16:45       ` Andy Moreton
@ 2018-09-12 17:10         ` Eli Zaretskii
       [not found]         ` <mailman.691.1536772269.1284.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2018-09-12 17:10 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Andy Moreton <andrewjmoreton@gmail.com>
> Date: Wed, 12 Sep 2018 17:45:35 +0100
> 
> 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.

Yes, MSYS2 moves more and more towards being just a variant of Cygwin
in this regard: a large number of "ported" packages are available just
as MSYS2 builds, which means you cannot easily run them from native
apps.

In this case, it should be trivial to provide a small batch file that
invokes "rcs ci" exactly like the shell script does.  Then native
programs, including Emacs, will be able to invoke the batch file as if
it were a program.  Alas, the MSYS2 guys evidently don't think this to
be important enough...

> 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.

FWIW, ye olde MSDOS port of Emacs is capable of running shell scripts,
but "sic transit gloria mundi".

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

I think it's much easier and safer to write a one-line batch file.

Thanks.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute shell scripts by call-process in msys2 environment
       [not found]         ` <mailman.691.1536772269.1284.help-gnu-emacs@gnu.org>
@ 2018-09-13  8:57           ` holgar.sperr
  0 siblings, 0 replies; 9+ messages in thread
From: holgar.sperr @ 2018-09-13  8:57 UTC (permalink / raw)
  To: help-gnu-emacs

Am Mittwoch, 12. September 2018 19:11:12 UTC+2 schrieb Eli Zaretskii:

[...]

> Yes, MSYS2 moves more and more towards being just a variant of Cygwin
> in this regard: a large number of "ported" packages are available just
> as MSYS2 builds, which means you cannot easily run them from native
> apps.
> 
> In this case, it should be trivial to provide a small batch file that
> invokes "rcs ci" exactly like the shell script does.  Then native
> programs, including Emacs, will be able to invoke the batch file as if
> it were a program.  Alas, the MSYS2 guys evidently don't think this to
> be important enough...

I am going to bring up this topic to the msys2 developers.

[...]

> 
>> The following advice works for me on emacs 26 and later to fix this
>> problem on Cygwin (MSYS2 should be similar):
> 
> I think it's much easier and safer to write a one-line batch file.
> 
> Thanks.

Since my Lisp is a bit rusty, I fixed the problem in my current setup
by one-line batch files and saved the Lisp functions for the future. 

Thanks to both of you for clarifying the subject.

Holger


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-09-13  8:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).